20
Display a F°/C° conversion table
- #include <stdio.h>
- /* print Fahrenheit-Celsius table
- for fahr = 0, 20, ..., 300 */
- #define LOW 0
- #define HIGH 300
- #define STEP 20
- main() {
- int fahr, celsius;
- int low = LOW; /* lower limit of temperature */
- int high = HIGH; /* upper limit */
- int step = STEP; /* step size */
- fahr = low;
- while( fahr <= high ) {
- celsius = 5 * (fahr-32) / 9;
- printf("%d\t%d\n", fahr, celsius);
- fahr = fahr + step;
- }
- }
$ gcc -o fahrencel1 fahrencel1.c
$ ./fahrencel1
0 -17
20 -6
40 4
60 15
80 26
100 37
120 48
140 60
160 71
180 82
200 93
220 104
240 115
260 126
280 137
300 148
- #include <stdio.h>
- /* Print Fahrenheit-Celsius table. */
- #define LOW 0
- #define HIGH 300
- #define STEP 20
- main() {
- int fahr;
- for( fahr = LOW; fahr <= HIGH; fahr += STEP )
- printf("%3d\t%6.2f\n", fahr, (5.0/9.0) * (fahr-32));
- }
$ gcc -o fahrencel fahrencel.c
$ ./fahrencel
0 -17.78
20 -6.67
40 4.44
60 15.56
80 26.67
100 37.78
120 48.89
140 60.00
160 71.11
180 82.22
200 93.33
220 104.44
240 115.56
260 126.67
280 137.78
300 148.89
Comments