練習1-4 編寫一個程式列印攝氏溫度轉換為響應華氏溫度的轉換表。
#include <stdio.h>
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
while (celsius <= upper) {
fahr = celsius * 9.0 / 5.0 + 32.0;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius += step;
}
return 0;
}
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
while (celsius <= upper) {
fahr = celsius * 9.0 / 5.0 + 32.0;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius += step;
}
return 0;
}
執行結果: