C程序设计语言 练习1-3

版权声明:转载时打个招呼。 https://blog.csdn.net/qq_15971883/article/details/89342005

练习1-3:修改温度转换程序,使之能在转换表的顶部打印一个标题。

#include <stdio.h>

/* 当fahr = 0, 20, 40, ..., 300时,打印华氏温度与摄氏温度对照表*/

int main(void)
{
    float fahr, celsius;

    int lower = 0;
    int upper = 300; 
    int step = 20; 

    fahr = lower; 
    printf("华氏温度-摄氏温度转换表\n");

    while (fahr <= upper)
    {
        celsius = (5.0 / 9.0) * (fahr - 32.0); 
        printf("%3.0f %6.1f\n", fahr, celsius);
        fahr += step; 
    }

    system("pause");
    return 0; 
}
运行结果

猜你喜欢

转载自blog.csdn.net/qq_15971883/article/details/89342005