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

Renuka said:   1 decade ago
Yes fmod is the correct ans as in for floating division.
(1)

Bibhas Kumar sahu said:   6 years ago
I don't understand this answer please explain me simply.
(4)

Renu said:   6 years ago
I don't understand this answer please explain me simply.
(5)

Keerthi said:   1 decade ago
Nice explanation given by premkumar now its very clear.

Kavita.C.Karjagar said:   1 decade ago
What is the function of fmod and were we can use fmod?

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

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

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

Nayan said:   8 years ago
What is the meaning of %lf ? Or why not use %f only?

JAY said:   1 decade ago
I think chandra also correct in the sence of maths.


Post your comments here:

Your comments will be displayed after verification.