Ads by ProfitSence
Close

C++ fmod()

Last Updated on Wednesday 5th Oct 2022

fmod

The fmod() function takes two arguments and the floating point remainder of numerator/denominator (rounded towards zero). It is defined in <cmath> header file.

Syntax

			
					fmod(double x, double y)

			
	

Parameters

The fmod() takes two arguments.

  • x: The first argument ( numerator )
  • y: The second argument ( denominator )

Return value

Returns the floating point remainder of x/y. If the denominator y is zero, fmod() returns NaN (Not a Number).

std fmod

fmod() prototype [As of C++ 11 standard]

			
					double fmod(double x, double y);
float fmod(float x, float y);
long double fmod(long double x, long double y);
double fmod(Type1 x, Type2 y);

			
	

math fmod

Example : C++ fmod()

			
					#include <stdio.h>
#include <math.h>

int main () {
  printf ( "fmod of 4.4 / 1.22 is %f\n", fmod (4.4,1.2) );
  printf ( "fmod of 11.11 / 2.2 is %f\n", fmod (11.11,2.2) );
  return 0;
}

			
	

Output

			
					fmod of 4.4 / 1.22 is 0.800000
fmod of 11.11 / 2.2 is 0.110000