The fmod
function calculates the remainder of the division of two numbers. Include the math.h
header file to use it.
fmod
is used when the argument has an int
type or a double
type.
double fmod(double x, double y)
x
: The numerator in the division (dividend)y
: The denominator in the division (divisor)x
/y
in floating-point representation.
It is equivalent to x - n*y
, where n
is equal to the quotient of x
/y
.The sign of the return value is the same as the sign of
x
.
fmod(0, y)
fmod(x, y)
fmod(x, ∞)
Return value: 0
, if y
is nonzero
Return value: NaN
, if either y
is 0
or x
is ∞
.
Return value:
x
, if x is not ∞
.
#include <stdio.h>#include <math.h>int main() {double x, y, result;x = 2.34;y = 1.5;result = fmod(x, y);printf("The remainder of %lf / %lf = %lf", x, y, result); //%lf is the string formatting placeholder for long floatreturn 0;}
In the example above, both parameters have acceptable values and the output produced is the remainder of their division.
Free Resources