That is because 9/5
is 1 and is type of integer. The fraction part is simply truncated. To achieve what you want, force the division to make floating point operations with 5.0/9
or 5/9.0
or 5.0/9.0
or (float) 5/9
When type of integer argument is bound with %f
, then the behaviour is undefined.
This is stated in C99 standard Section 7.21.6.1 Paragraph 9. This paragraph is quoted below:
If a conversion specification is invalid, the behavior is
undefined. If any argument is not the correct type for the
corresponding conversion specification, the behavior is undefined.