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