华氏温度与摄氏温度对照表

华氏温度与摄氏温度对照表

C语言代码块

#include<stdio.h>
      2 
      3 
      4 main()
      5 {
    
    
      6         int fahr,celsius;
      7         int lower,upper,step;
      8         lower=0;  //温度表的下限
      9         upper=300;  //温度表的上限
     10         step=10;  //步长
     11         fahr=lower;
     12         while(fahr<=upper)
     13         {
    
    
     14                 celsius=5*(fahr-32)/9;  /*计算指定华氏度转换成摄氏度,必须先乘5再除以9,因为整数除法进行舍位。*/
     15                 printf("%d\t%d\n",fahr,celsius);
     16                 fahr=fahr+step;
     17         }
     18 }

结果如下

[root@localhost boke]# ./a.out
0       -17
10      -12
20      -6
30      -1
40      4
50      10
60      15
70      21
80      26
90      32
100     37
110     43
120     48
130     54
140     60
150     65
160     71
170     76
180     82
190     87
200     93
210     98
220     104
230     110
240     115
250     121
260     126
270     132
280     137
290     143
300     148

猜你喜欢

转载自blog.csdn.net/weixin_45802444/article/details/103123493