Related Articles
C | Data Types | Question 3
• Difficulty Level : Easy
• Last Updated : 01 Aug, 2017

Predict the output

 `#include `` ` `int` `main()``{``   ``float` `c = 5.0;``   ``printf` `(``"Temperature in Fahrenheit is %.2f"``, (9/5)*c + 32);``   ``return` `0;``}`

(A) Temperature in Fahrenheit is 41.00
(B) Temperature in Fahrenheit is 37.00
(C) Temperature in Fahrenheit is 0.00
(D) Compiler Error

Answer: (B)

Explanation: Since 9 and 5 are integers, integer arithmetic happens in subexpression (9/5) and we get 1 as its value.

To fix the above program, we can use 9.0 instead of 9 or 5.0 instead of 5 so that floating point arithmetic happens.

 `#include `` ` `int` `main()``{``   ``float` `c = 5.0;``   ``printf` `(``"Temperature in Fahrenheit is %.2f"``, (9.0/5)*c + 32);``   ``return` `0;``}`

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up