Predict the output
#include <stdio.h>
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 <stdio.h>
int main()
{
float c = 5.0;
printf ( "Temperature in Fahrenheit is %.2f" , (9.0/5)*c + 32);
return 0;
}
|
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
01 Aug, 2017
Like Article
Save Article