+ 2
What is the valid code for including modulo division operator in a c ??
4 odpowiedzi
+ 10
see this example how to calculate modulo of float types Values
#include <stdio.h>
#include <math.h>
int main () {
float a, b;
int c;
a = 9.2;
b = 3.7;
c = 2;
printf("Remainder of %f / %d is %lf\n", a, c, fmod(a,c));
printf("Remainder of %f / %f is %lf\n", a, b, fmod(a,b));
return(0);
}
+ 8
First read basics about modulo and / how its working may be you asking for float and double value how u can get Remainder for these data type because u cannot get modulo directly with modulo operator.
When I use % operator on float values I get error stating that "invalid operands to binary % (have ‘float’ and ‘double’)".I want to enter the integers value only but the numbers are very large(not in the range of int type)so to avoid the inconvenience I use float.
fmod() provides the necessary function. As has not yet been noted, it's important to realize that rounding errors in the second operand of fmod may cause unexpected behaviors. For example, fmod(1, 0.1); should mathematically be zero, but will in fact be almost 0.1. The extent of error goes up with the magnitude of the quotient. For example, fmod(9E14, 0.1); evaluates to about 0.05,
+ 1
I want to know that , how we can include modulo division operator in float values ??
0
Thanks , I got it