Why is celsius = 5 * (fahr – 32) / 9
Mar 16, 2015
There is a program to print Fahrenheit-Celsius table as below.
1 |
|
The right part of the figure is the output of this program. The Celsius temperature is computed and assigned to the variable celsius
by the statement
1 | celsius = 5 * (fahr - 32) / 9; |
The reason for multiplying by 5 and then dividing by 9 instead of just multiplying by 5/9 is that in C, as in many other languages,integer division truncates: any fractional part is discarded. Since 5 and 9 are integers, 5/9 would be truncated to zero and so all the Celsius temperatures would be reported as zero.
Reference