C Program for Temperature Conversion from Fahrenheit to Celsius.
K&R C Program Exercise 1-03 Problem :
Modify the temperature conversion program to print a heading above the table.
C Program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <stdio.h> int main(void) { float fahrenheit, celsius; int lower, upper, step; lower = 0; upper = 200; step = 20; printf(" F\tC"); printf("\n------------"); fahrenheit = lower; while (fahrenheit <= upper) { celsius = (5.0 / 9.0) * (fahrenheit - 32.0); printf("\n%3.0f %6.1f", fahrenheit, celsius); fahrenheit = fahrenheit + step; } return 0; } |
Output of Program :
1 2 3 4 5 6 7 8 9 10 11 12 13 | F C ------------ 0 -17.8 20 -6.7 40 4.4 60 15.6 80 26.7 100 37.8 120 48.9 140 60.0 160 71.1 180 82.2 200 93.3 |