+ 2

What is the valid code for including modulo division operator in a c ??

18th Aug 2020, 2:36 PM
Jaywardhan
6 Answers
+ 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); }
19th Aug 2020, 6:19 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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,
19th Aug 2020, 6:17 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
I want to know that , how we can include modulo division operator in float values ??
19th Aug 2020, 5:24 AM
Jaywardhan
0
Thanks , I got it
19th Aug 2020, 2:51 PM
Jaywardhan