C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 1)
1.
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?
rem = 3.14 % 2.1;
rem = modf(3.14, 2.1);
rem = fmod(3.14, 2.1);
Remainder cannot be obtain in floating point division.
Answer: Option
Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point divisions.

Example:


#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) );
  return 0;
}

Output:
fmod of 3.14/2.1 is 1.040000

Discussion:
141 comments Page 2 of 15.

Sugandha Singh said:   1 decade ago
It means % operator is use when we are doing integer division to get the remainder?
(1)

Md imran khan said:   1 decade ago
Which function is called global and local function? Can anybody help me?
(1)

Subrat said:   8 years ago
@Dinesh Kumar.

#include<stdio.h>
int main()
{
int a=1;
printf("%d %d %d",a,a++,++a);
return 0;
}
Output : 3 2 3.
But logically 3 2 2.

Can any explain how 3 2 3 comes?

Your logic is true,function data passing is from right to left. So first ++a execute then a++,then a.
But the current value of a will be substitute in pre-increment operator always.
So the output will be 3 2 3.
(1)

Subrat said:   8 years ago
#include <stdio.h>
#include <math.h>

int main ()
{
float 3.13.2.1;
float R;
R=fmod(3.14,2.1);
printf ("The remainder is:",R);
scanf("%f",R);
return 0;
}

It will show error, because you write
float 3.13.2.
(1)

Silambu said:   7 years ago
No @Keerthi.

The floating point remainder cannot be obtained by modulo operator.
(1)

Bhuvana said:   7 years ago
Option C is correct. Thanks
(1)

Sakshi Deshmukh said:   2 years ago
Good answer, Thanks all for the explanation.
(1)

Shan said:   2 decades ago
What is the work of the fmod?

Nidhi said:   2 decades ago
The answer could be option A (i.e) rem = 3.14 % 2.1 ?

Chandra said:   2 decades ago
% operator represents Reminder in C Language
But it is not possible for floating point operations.So,the Answer would be option (d).

(d)Remainder cannot be obtain in floating point division.


Post your comments here:

Your comments will be displayed after verification.