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

Shubhangi said:   2 years ago
@All.

The % modulus operator gives a remainder of only int and not applicable for float.
(26)

Narayana reddy said:   1 decade ago
Is it possible take this in to EXE file to run other than c compiler please tell me.

Ajinkya said:   1 decade ago
What is the difference between

rem = modf(3.14, 2.1);
rem = fmod(3.14, 2.1);

?

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

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

Silambu said:   7 years ago
No @Keerthi.

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

Sivaraman said:   1 decade ago
It's really not understand me, please briefly explain it for modf() and fmod().

Kennedy muriuki said:   8 years ago
I support answer C, fmod should be used in float where we need decimal points.

Sri said:   1 decade ago
Why we can use the fmod? instead of that what word is apt for the execution.

Pooja Papule said:   1 decade ago
But % operator also gives remainder in output.... So, we can also use %....


Post your comments here:

Your comments will be displayed after verification.