C Standard Library
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C <math.h> - fmod() Function

The C <math.h> fmod() function returns the floating-point remainder of x/y (rounded towards zero). This can be mathematically expressed as below:

fmod = x - tquot * y

Where tquot is the result of x/y rounded toward zero.

Note: The remainder function is similar to the fmod function except the quotient is rounded to the nearest integer instead of towards zero.


double fmod (double x, double y);
float fmodf (float x, float y);
long double fmodl (long double x, long double y);


x Specify the value of numerator.
y Specify the value of denominator.

Return Value

Returns remainder of x/y. If y is zero, the function may either return zero or cause a domain error (depending on the library implementation).


In the example below, fmod() function is used to find out the remainder of a given division.

#include <stdio.h>
#include <math.h>
int main () {
  printf("%lf\n", fmod(25, 4));
  printf("%lf\n", fmod(20, 4.9));
  printf("%lf\n", fmod(20.5, 2.1)); 
  return 0;

The output of the above code will be:


❮ C <math.h> Library