Home >>C Math Functions >C math fmod() function

C math fmod() function

C math fmod() function

The C math fmod() function is used to return the remainder of x divided by y. It takes two different arguments x & y, one as a divisor and other as dividend and returns the value in type double. It is defined in <math.h> header file.

Syntax:
double fmod(double x, double y)

Parameter Values

Parameter Description
x It is the floating point value with the division numerator.
y It is the floating point value with the division denominator.
Here is an example of fmod() function:

#include <stdio.h>
#include <math.h>
int main () 
{
float a, b;
int c;
a = 9.2;
b = 3.7;
c = 2;
printf("Remainder of %f / %d is %lf\n", a, c, fmod(a,c));
printf("Remainder of %f / %f is %lf\n", a, b, fmod(a,b));
return(0);
}

Output:
Remainder of 9.200000 / 2 is 1.200000
Remainder of 9.200000 / 3.700000 is 1.800000
Example-2

#include <stdio.h>
#include <math.h>
int main () 
{
float a, b;
int c;
a = 63;
b = 3;
c = 2;
printf("Remainder of %f / %d is %lf\n", a, c, fmod(a,c));
printf("Remainder of %f / %f is %lf\n", a, b, fmod(a,b));
return(0);
}

Output:
Remainder of 63.000000 / 2 is 1.000000
Remainder of 63.000000 / 3.000000 is 0.000000

No Sidebar ads