Exercise 1-4. Write a program to print the corresponding Celsius to Fahrenheit table.
写一个摄氏度转换成华氏度的程序,这里我们还是假定从0-300,步长20。
根据华氏度转换摄氏度的公式:
得到摄氏度转换成华氏度的公式为:
所以我们的转换语句可以改成:
fahr = (9.0 * celsius / 5.0) + 32;
完整代码为:
#include <stdio.h>
main() {
float fahr, celsius;
float lower, upper, step;
lower = 0;
upper = 300;
step = 20;
celsius = lower;
printf("Celsius\tFahr\n");
while (celsius <= upper) {
fahr = (9.0 * celsius / 5.0) + 32;
printf("%7.0f\t%4.1f\n", celsius, fahr);
celsius = celsius + step;
}
}
输出结果为:

本文提供了一个C程序,用于打印0到300摄氏度每20度对应的华氏度表格。程序依据摄氏度转华氏度公式,通过循环输出转换结果。
最低0.47元/天 解锁文章
282

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



