What is fmod in C?

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.

Prototype

double fmod(double x, double y)

Parameter and return values

Parameters

  • x: The numerator in the division (dividend)
  • y: The denominator in the division (divisor)

Return value

  • The remainder of 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.

Special cases

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 .

Code

#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 float
return 0;
}

In the example above, both parameters have acceptable values and the output produced is the remainder of their division.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved