#include <stdio.h>
// 函式宣告
float CelsiustoFahrenheit(int tc);
int main() {
int tc;
float tf;
// 提示使用者輸入攝氏溫度
printf("請輸入攝氏溫度: ");
scanf("%d", &tc);
// 調用函數轉換溫度並列印結果
tf = CelsiustoFahrenheit(tc);
printf("%d 攝氏度等於 %.2f 華氏度。\n", tc, tf);
return 0;
}
// 函式定義
float CelsiustoFahrenheit(int tc) {
return tc * 1.8 + 32;
}
這段程式首先定義了CelsiustoFahrenheit函數,用於實現攝氏溫度到華氏溫度的轉換。然後,在main函數中,程式提示使用者輸入攝氏溫度值,接收這個值並存儲在變數tc中。之後,程式調用CelsiustoFahrenheit函數將攝氏溫度轉換為華氏溫度,並將轉換後的華氏溫度值存儲在變數tf中。最後,程式列印出攝氏溫度和對應的華氏溫度。