w3resource

C fmod() function

C fmod() function - Calculate Floating-Point remainder

Syntax:

double fmod(double x, double y)

The fmod() function is used to calculate the floating-point remainder of x/y. The absolute value of the result is always less than the absolute value of y and the result will have the same sign as x.

Parameters:

Name Description Required /Optional
x Floating-point value. Required
y Floating-point value. Required

Return value from fmod()

  • Returns the floating-point remainder of x/y.
  • If y is zero or if x/y causes an overflow, fmod() returns 0.

Example: fmod() function

The following example shows the usage of fmod() function.


#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double x, y, result;
   x = 200.0;
   y = 7.0;
   printf("Before applying fmod()");
   printf("\nx = %lf", x);
   printf("\ny = %lf", y);    
   result = fmod(x,y);
   printf("\n\nAfter applying fmod()");
   printf("\nResult = %lf", result);
   x = -45.0;
   y = 4.0;
   printf("\n\nBefore applying fmod()");
   printf("\nx = %lf", x);
   printf("\ny = %lf", y);    
   result = fmod(x,y);
   printf("\n\nAfter applying fmod()");
   printf("\nResult = %lf", result);
   
}

Output:

Before applying fmod()
x = 200.000000
y = 7.000000

After applying fmod()
Result = 4.000000

Before applying fmod()
x = -45.000000
y = 4.000000

After applying fmod()
Result = -1.000000

C Programming Code Editor:

Previous C Programming: C floor()
Next C Programming: C math.h Home



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming/math/c-fmod.php