练习1-15使用函数实现温度转换

这道题是C程序语言设计中的练习1-15.

只是基本实现,若有错误或更优秀的方法,欢迎指正,谢谢。

#include <stdio.h>
//当fahr = 0,20,..., 300时,分别打印华氏温度与摄氏温度对照表
int  celsius(float a, int b, int c);

main()
{
    float fahr;
    int lower, upper;
    int step;
    
    lower = 0; //温度表的下限
    upper = 300; //温度表的上限
    step = 20; //步长
    
    fahr = lower;
    printf("The fahr and celsius.\n");
    celsius(fahr,upper,step);
    
    return 0;
    
}

//转换函数
int  celsius(float fahr, int upper, int step)
{
    int i;
    for(i=fahr;i<=upper;i+=step){
        printf("%3.0f %6.1f\n", fahr, (5.0 / 9.0 * (fahr-32.0)));
        fahr += step;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/secret_lee/article/details/80027111
今日推荐