This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

11 Nov 2012

HOW TO PERFORM % OPERATION ON DOUBLE VALUES/ FMOD( ) FUNCTION IN C

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. 

-> fmod( ) return type is double. So, we use %lf specifier when it is used .

#include<math.h>
double fmod(double numerator,double denominator)

Example programs to understand fmod() function :

void main()
{
  int a ;
 printf("%lf",fmod(10.5%3));
}

output: 1.500000
--------------------------------------


void main()
{
  float a=10.0%3;
  printf("%lf",a);
}
output: shows error like Illegal use of floating point.

No comments:

Post a Comment

Thanks for your comments.
-Sameer