C fmod Function: Usage & Examples
The fmod function is a mathematical library function in the C language, used to calculate the remainder of two floating-point numbers. Its prototype is as follows:
double fmod(double x, double y);
In this case, x and y represent the dividend and divisor, and the function returns the remainder of x divided by y.
The steps for using the fmod function are as follows:
- import the math.h library
- Calculate the remainder of dividing x by y and store it in the variable result.
- Handle the return value: store the remainder of x divided by y in the result variable.
Sample code:
#include <stdio.h>
#include <math.h>
int main() {
double x = 10.5;
double y = 3.0;
double result = fmod(x, y);
printf("x除以y的余数为: %.2f\n", result);
return 0;
}
The above code will display: the remainder of x divided by y is 1.50.