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

Peter Omondi said:   5 years ago
Well understood. Thanks all for explaining.
(3)

Manikandan said:   1 decade ago
What is the differnce b/w fmod and modf ?

Mani said:   1 decade ago
2)16(8
16
------------
0

Rem = 0.

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

Ratnaprakash said:   1 decade ago
Me too want to know about fmod&modf.

Bhanu said:   9 years ago
Nice explanation @Prem Kumar. Thank you.

Dhara said:   1 decade ago
What different between fmod & modf?

Karri jagapathibabu said:   9 years ago
Please tell me what is the use of fmod?

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

Dipak said:   5 years ago
@All.

We can't apply % sign on float.
(7)


Post your comments here:

Your comments will be displayed after verification.