cpelles-c

Weird output with pelles c


float f=44268/107402;
printf("\n%f",f);

output :

0.000000

How can this happen!

I am using pelles c ide on win 7.


Solution

  • The compiler treats the operands as integers. Try:

    float f = 44268.0 / 107402;
                    ^
    

    Or maybe

    float f = (float)44268 / 107402;