练习2-12 输出华氏-摄氏温度转换表 (15 分)

练习2-12 输出华氏-摄氏温度转换表 (15 分)

输入2个正整数lowerupperlowerupper≤100),请输出一张取值范围为[lowerupper]、且每次增加2华氏度的华氏-摄氏温度转换表。

温度转换的计算公式:,其中:C表示摄氏温度,F表示华氏温度。

输入格式:

在一行中输入2个整数,分别表示lowerupper的值,中间用空格分开。

输出格式:

第一行输出:"fahr celsius"

接着每行输出一个华氏温度fahr(整型)与一个摄氏温度celsius(占据6个字符宽度,靠右对齐,保留1位小数)。

若输入的范围不合法,则输出"Invalid."。

输入样例1:

32 35

输出样例1:

fahr celsius
32   0.0
34   1.1

输入样例2:

40 30

输出样例2:

Invalid.




#include <stdio.h>
#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
int f,a,b;
double c;
scanf("%d %d",&a,&b);

if (a<=b&&b<=100){
printf("fahr celsius\n");

for(f=a;f<=b;f+=2){
c=5.0*(f-32)/9.0;
printf("%d%6.1f\n",f,c);}

}
else
printf("Invalid.");

return 0;
}

 

猜你喜欢

转载自www.cnblogs.com/xxl-h/p/11110965.html