Exercise 1-5 (Temperature reverse)
Chapter_1 Exercise_1-4 for()_variant | #define_directive Exercise_1-6 |
Exercise 1-5 K&R, p. 14
Exercise 1-5. Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.
fahrr.c download
#include <stdio.h> // for printf()
// print Fahrenheit-Celsius table in reverse order
int main()
{
int fahr;
for (fahr = 300; fahr >= 0; fahr -= 20)
{printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));}
}
/*
gcc fahrr.c -o fahrr
./fahrr
300 148.9
280 137.8
260 126.7
240 115.6
220 104.4
200 93.3
180 82.2
160 71.1
140 60.0
120 48.9
100 37.8
80 26.7
60 15.6
40 4.4
20 -6.7
0 -17.8
*/
Chapter_1 Exercise_1-4 for()_variant | BACK_TO_TOP | #define_directive Exercise_1-6 |
Comments
Post a Comment