What is fmodf in C?
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.
fmodfuses arguments of typefloat.
Prototype
float fmodf(float x, float y)
Parameter and return value
Parameters
x: floating-point numerator in the division (divisor)y: floating-point denominator in the division (dividend)
Return value
- A
floattype remainder ofx/yis returned. The return value is equivalent tox - n*y, where n is equal to the quotient ofx/y.
The return value’s sign is the same as the sign associated with
x.
Special cases
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 ∞.
Code
#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
Copyright ©2026 Educative, Inc. All rights reserved