fmod() returns the floating-point remainder of x / y. The result has the same sign as x. It is different from the integer-only % operator.
double fmod(double x, double y);
#include <math.h>
#include <stdio.h>
int main(void) {
double x = 17.5;
double y = 4.0;
printf("Remainder: %.2f\n", fmod(x, y));
return 0;
}
Output
Remainder: 1.50
#include <math.h>
#include <stdio.h>
int main(void) {
printf("%.2f\n", fmod(-17.5, 4.0));
return 0;
}
Output
-1.50
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.