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 ?
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 4 of 15.
Kavita.C.Karjagar said:
1 decade ago
What is the function of fmod and were we can use fmod?
Prathamesh m. patkar said:
1 decade ago
Yes, because the given values are in floating type so we also want the ans in floating type therefore we use fmod().
Sivakumar said:
1 decade ago
I want to know clear difference between fmod() and modf().
Vijay said:
1 decade ago
What is the difference between %, mod(), fmod() and modf()?
Ratnaprakash said:
1 decade ago
Me too want to know about fmod&modf.
Prem kumar said:
1 decade ago
modf->Breaks x into two parts: the integer part (stored in the object pointed by intpart) and the fractional part (returned by the function).
Each part has the same sign as x.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
/* modf example */
#include <stdio.h>
#include <math.h>
int main ()
{
double param, fractpart, intpart;
param = 3.14159265;
fractpart = modf (param , &intpart);
printf ("%lf = %lf + %lf \n", param, intpart, fractpart);
return 0;
}
Output:
3.141593 = 3.000000 + 0.141593
Each part has the same sign as x.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
/* modf example */
#include <stdio.h>
#include <math.h>
int main ()
{
double param, fractpart, intpart;
param = 3.14159265;
fractpart = modf (param , &intpart);
printf ("%lf = %lf + %lf \n", param, intpart, fractpart);
return 0;
}
Output:
3.141593 = 3.000000 + 0.141593
Velmani said:
1 decade ago
% (%d)is used for only integer datatype. % is does not used for float datatype. So if you need mod in deciamal number then you can use fmod(%f) function.
Saikiran said:
1 decade ago
What Prem Kumar comented is correct.
Saikiran said:
1 decade ago
#include<stdio.h>
#include<math.h>
int main()
{
float i,j;
i=3.14;j=2.1;
printf("\ni modulo j is %f",fmod(i,j));
return 0;
}
O/P:
i modulo j is 1.040000
#include<math.h>
int main()
{
float i,j;
i=3.14;j=2.1;
printf("\ni modulo j is %f",fmod(i,j));
return 0;
}
O/P:
i modulo j is 1.040000
Mounika said:
1 decade ago
Yes renuka is right.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers