How to perform Modulus / Mod operator on double values (OR) FMOD( ) function in C Programming
Before you go through this post go for the link to know about % operator.
-> As % operator cannot used with DOUBLE values, as it generates compile time error, there is a special function ” fmod( ) ” in c.
-> As % operator cannot used with DOUBLE values, as it generates compile time error, there is a special function ” fmod( ) ” in c.
-> fmod( ) return type is double. So, we use %lf specifier when it is used .
1 |
#include<math.h> |
1 |
double fmod(double numerator,double denominator) |
Example programs to understand fmod() function :
1 2 3 4 5 |
void main() { int a ; printf("%lf",fmod(10.5%3)); } |
1.500000
1 2 3 4 5 |
void main() { float a=10.0%3; printf("%lf",a); } |
output: shows error like Illegal use of floating point.