float f=44268/107402;
printf("\n%f",f);
output :
0.000000
How can this happen!
I am using pelles c ide on win 7.
float f=44268/107402;
printf("\n%f",f);
output :
0.000000
How can this happen!
I am using pelles c ide on win 7.
The compiler treats the operands as integers. Try:
float f = 44268.0 / 107402;
^
Or maybe
float f = (float)44268 / 107402;
Integer division truncates
float f=44268.0/107402;
Making one number float will automatically promote the other number ti float as well finally ending up in a floating point result.
float f = 44268 / 107402;
The variable will be initialize with an integer value. You should add a floating point, to say to the compiler that you want a float value.
float f = 44268. / 107402.;