Go to my personal blog
There is a program to print Fahrenheit-celsius table as below.
#include <stdio.h>/* print Fahrenheit-celsius table for Fahr = 0, ..., + */int main () {int Fahr, celsius;in t lower, upper, step;lower = 0; /* Lower limit of temperature table */upper =; /* Upper Limit */step =; /* Step Size */fahr = Lower;while (Fahr <= Upper) {Celsius = 5 * (fahr-32)/9;printf ("%d\t%d\n", Fahr, Celsius); Fahr = Fahr + Step;}}
The right part of the are the output of this program . The Celsius temperature is computed and assigned to the variablecelsius
By the statement
Celsius = 5 * (fahr-32)/9;
The reason for multiplying by 5 and then dividing by 9 instead of just multiplying by 5/9 are that in C, as in many other L Anguages, integer division truncates: Any fractional part is discarded. Since 5 and 9 are integers, 5/9 would is truncated to zero and so all the Celsius temperatures would is reported as zero.
Referencethe C Programming Language
Why Celsius = 5 * (fahr-32)/9?