modified lenhist
[KandRexercises.git] / 1-15.c
blobd7e3142d1b390d320cc01b1056994c77ad25c973
1 #include <stdio.h>
2 /* exercise 1-15: exercise 1-3 but with a function */
3 /* print Fahrenheit-Celsius table
4 for fahr = 0, 20, ..., 300; floating-point version */
5 int fahrc(float lower, float upper, float step)
7 float i;
9 printf("Fahr\tC\n");
10 for (i = lower; i <=upper; i += step)
11 printf("%3.0f %6.1f\n", i, ((5.0/9.0) * (i-32.0)));
13 return 0;
16 main()
18 float fahr, celsius;
19 float lower, upper, step;
21 lower = 0; /* lower limit of temperatuire scale */
22 upper = 300; /* upper limit */
23 step = 20; /* step size */
24 fahrc(lower, upper, step);
26 /*fahr = lower;
27 printf("Fahr\tC\n");
28 while (fahr <= upper) {
29 celsius = (5.0/9.0) * (fahr-32.0);
30 printf("%3.0f %6.1f\n", fahr, celsius);
31 fahr = fahr + step;
32 }*/