1-4、用c语言编写一个用于打印摄氏与华氏温度对照表的程序
#include <stdio.h>
void main()
{
float fah,cel;
int upper, lower, step;
upper = 300;
lower = 0;
step = 1;
cel = lower;
printf("cel\tfah\n");
while(cel <= upper)
{
fah = (9.0/5.0)*cel + 32;
printf("%3.0f\t%6.1f\n",cel,fah);
cel = cel + step;
}
}
for循环实现
#include <stdio.h>
void main()
{
int cel;
for(cel = 0; cel <=300; cel = cel+20 )
{
printf("%d\t%.1f\n",cel,(9.0/5.0)*cel+32);
}
}