fmod() Function Tutorial In C++

C++ programming language provides the fmod() function in order to calculate the remainder of a division. The fmod() returns the floating-point remainder of number/denom. The fmod() function is provided with the math.h header.

fmod() Function Syntax

The syntax of the fmod() function is like below.

double fmod(double NUMER,double DENOM)
  • NUMER is the double or floating point numer which mod will be calculated according to DENOM.
  • DENOM is used for modcalculation.

Calculate Floating Point Mod

#include <stdio.h>      /* printf */
#include <math.h>       /* fmod */

int main ()
{
  printf ( "fmod of 3.5 / 2 is %f\n", fmod (3.5,2) );
  printf ( "fmod of 28.5 / 4.11 is %f\n", fmod (28.5,4.11) );
  return 0;
}
fmod of 3.5 / 2 is 1.500000
fmod of 28.5 / 4.11 is 3.840000

Leave a Comment