The fmodf
function, a variation of the fmod
function, calculates the remainder of the division of two numbers. It is available for use in the math.h
header file.
fmodf
uses arguments of typefloat
.
float fmodf(float x, float y)
x
: floating-point numerator in the division (divisor)y
: floating-point denominator in the division (dividend)float
type remainder of x
/y
is returned. The return value is equivalent to x - n*y
, where n is equal to the quotient of x
/y
.The return value’s sign is the same as the sign associated with
x
.
fmodf(0, y)
fmodf(x, y)
fmodf(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() {float a, b, result;a = 10.4;b = 3.5;result = fmodf(a, b);printf ("The remainder is: %f", result); // %f is the string formatting placeholder for a floating-point numberreturn 0;}
In the code above, two floating-point numbers are passed as arguments to fmodf
. The returned floating-point number is stored in the result
variable, then it’s displayed.
Free Resources