#include <stdio.h>
int main() {
printf("\nRemainder = %.2f", fmod(14,3)); // Remainder= 2.00
printf("\nRemainder = %.2f", fmod(3,14)); // Remainder= 3.00
printf("\nRemainder = %.2f", fmod(-14,3)); // Remainder= -2.00
printf("\nRemainder = %.2f", fmod(14,0)); // Remainder= -nan
printf("\nRemainder = %.2f", fmod(14,2)); // Remainder= 0.00
return 0;
}
We will get reminder of a division by using %
operator .
x % y
x = division numerator number
y = division denominator number
Example with integer as inputs
#include <stdio.h>
#include <math.h>
int main(void){
long int x,y , z;
x=13;
y=3;
z = (x % y);
printf("%d ", z);
return 0;
}
The above code will give this output.
1
Example with float variables by using fmod()
#include <stdio.h>
#include <math.h>
int main(void){
float x,y , z;
x=13.345;
y=2.32;
z = fmod(x, y);
printf("%f ", z);
return 0;
}
Output is here
1.745001