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

Piyush said:   7 years ago
Why option A is incorrect?

Vignesh said:   1 decade ago
What is the work of fmod?

Harshada said:   1 decade ago
Yes Prem Kumar is right.

Vela said:   10 years ago
Given explain is well.

Mounika said:   1 decade ago
Yes renuka is right.

Shikha said:   9 years ago
Is fmod used in PHP?

Keerthi said:   7 years ago
Option A is correct.

Anjali said:   1 decade ago
What is return 0?

Nagendran said:   1 decade ago
Good explanation

Rajasekar said:   1 decade ago
Its very nice.


Post your comments here:

Your comments will be displayed after verification.