练习题1-3,修改温度转换程序,使之打印出一个标题:
- #include <stdio.h>
- /* print Fahrenheit-Celsius table
- for fahr = 0, 20, ..., 300; floating-point version */
- main()
- {
- float fahr, celsius;
- float lower, upper, step;
-
- lower = 0; /* lower limit of temperatuire scale */
- upper = 300; /* upper limit */
- step = 20; /*step size */
-
- printf("Fahrenheit-Celsius\n");
- fahr = lower;
- while (fahr <= upper) {
- celsius = (5.0/9.0) * (fahr-32.0);
- printf("%10.0f %7.1f\n", fahr, celsius);
- fahr = fahr + step;
- }
- }
输出如下:
- Fahrenheit-Celsius
- 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
- 220 104.4
- 240 115.6
- 260 126.7
- 280 137.8
- 300 148.9
阅读(814) | 评论(0) | 转发(0) |