int a = 9/5;
performs integer division and ignores the remainder, so a
is set to 1. Attempting to print that using %f
gives undefined behavior, but by chance you got 0.000000
out of it.
Do
double a = 9./5.;
instead, or print with %d
if integer division was the desired behavior. (float
would also work, but a
will be promoted to double
when passed to printf
, so there's no reason not to use double
.)