PAT 5-9 输出华氏-摄氏温度转换表   (10分)

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

温度转换的计算公式:C=5×(F−32)/9C = 5 imes (F - 32) / 9C=5×(F32)/9,其中:CCC表示摄氏温度,FFF表示华氏温度。

输入格式:

在一行中输入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.
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<string>
 5 #include<algorithm>
 6 #include<cmath>
 7 using namespace std;
 8 
 9 int main()
10 {
11     int l,u,i;
12     scanf("%d%d",&l,&u);
13     if(l>u)
14         printf("Invalid.
");
15     else
16     {
17         printf("fahr celsius
");
18         for(i=l;i<=u;i+=2)
19             printf("%d%6.1lf
",i,5.0*(double)(i-32)/9.0);//输出占六个字符%6.1lf
20     }
21     return 0;
22 }
原文地址:https://www.cnblogs.com/Annetree/p/6504549.html