C程序设计语言(第2版·新版)练习题1-4

练习1-4 编写一个程序打印摄氏温度转换为响应华氏温度的转换表。

#include <stdio.h>

int main(int argc, char *argv[]) {
    (void) argc;
    (void) argv;
    
    float fahr, celsius;
    int lower, upper, step;
    
    lower = 0;
    upper = 300;
    step = 20;
    
    fahr = lower;
    while (celsius <= upper) {
        fahr = celsius * 9.0 / 5.0 + 32.0;
        printf("%3.0f %6.1f\n", celsius, fahr);
        celsius += step;
    }
    return 0;
}

运行结果:

 

posted @ 2024-08-24 14:33  gongwenjun  阅读(50)  评论(0)    收藏  举报