Easy Tutorial
❮ C Exercise Example23 C Function Strerror ❯

C Library Function - fmod()

C Standard Library - <math.h>

Description

The C library function double fmod(double x, double y) returns the remainder of x divided by y.

Declaration

Following is the declaration for the fmod() function.

double fmod(double x, double y)

Parameters

Return Value

The function returns the remainder of x/y.

Example

The following example demonstrates the use of the fmod() function.

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

int main ()
{
   float a, b;
   int c;
   a = 9.2;
   b = 3.7;
   c = 2;
   printf("%f / %d 的余数是 %lf\n", a, c, fmod(a,c));
   printf("%f / %f 的余数是 %lf\n", a, b, fmod(a,b));

   return(0);
}

Let's compile and run the above program, which will produce the following result:

9.200000 / 2 的余数是 1.200000
9.200000 / 3.700000 的余数是 1.800000

C Standard Library - <math.h>

❮ C Exercise Example23 C Function Strerror ❯