任务:
根据给出的格式要求输出摄氏-华氏温度对应表。
温度转换公式:华氏温度=9/5∗摄氏温度+32
要求:
输出摄氏-华氏温度对应表。每行输出格式要求:摄氏温度和华氏温度均为单精度浮点数,都各占8个字符位宽,精度取2;摄氏温度前一个 tab 键,摄氏温度和华氏温度间以一个 tab 键相隔(摄氏温度从−30°循环到30°)。
预期输出:
摄氏温度 华氏温度-30.00 -22.00-25.00 -13.00-20.00 -4.00-15.00 5.00-10.00 14.00-5.00 23.000.00 32.005.00 41.0010.00 50.0015.00 59.0020.00 68.0025.00 77.0030.00 86.00
参考:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float c;
printf("\t摄氏温度\t华氏温度\n");
for(c=-30;c<=30;c=c+5)
printf("\t%8.2f\t%8.2f\n",c,(9.0/5.0)*c+32);
return 0;
}
或用while循环:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int f,step;
float c = -30.0;
step = 5;
printf("华氏温度\t摄氏温度\n");
while(c<=30)
{
f = 9.0/5*c+32;
printf("%d\t%.6f\n",f,c);
c+=step;
}
return 0;
}



901

被折叠的 条评论
为什么被折叠?



