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 5 of 15.

PRIYANKA said:   10 years ago
Modulus support only integers. For ex: If we take 16.25/2.5 then in modulus it take only 16 from 16.25 and from 2.5 it takes 2 and gives answer 4. It performs on integers only.

fmod gives reminder in float.

Hope it clear.

Vela said:   10 years ago
Given explain is well.

Deepika said:   10 years ago
What is difference between fmod and modf?

Kalpanadevi said:   10 years ago
What is the maximum numbers of parameters that can be passed in printf and scanf?

Madhuri said:   10 years ago
Nice explanation but I am not clear about increment.

Amer patel said:   10 years ago
If you use % for fining remainder it will give you an integer value.

But the fmmod() function gives you remainder in floating point value.

Rey said:   10 years ago
What is REM?

And I also need some information about what is the difference between.

Rem = 3.14% 2.1; and rem = fmod (3.14, 2.1);

Gayathridhiravidamani said:   1 decade ago
#include<stdio.h>
main()
{
float a=3.14,b=2.1,c;
c=a%b;
pf("%d",c);
output: invalid operand to binary%
BUT
int a;
a=3.14%2.1;
pf("%d",a);

Output 1:

I think so, comma act as a operator. Please clear explanation.

Shalivahana said:   1 decade ago
fmod() function or keyword is find used to find out.

Rajashekhar said:   1 decade ago
int main()? What's the function it is?


Post your comments here:

Your comments will be displayed after verification.