C 語言溫度華氏度到攝氏度轉換程式


給定華氏度溫度“n”,“挑戰”是將給定的溫度轉換為攝氏度並顯示它。

例如

Input 1-: 132.00
Output -: after converting fahrenheit 132.00 to celsius 55.56
Input 2-: 456.10
Output -: after converting fahrenheit 456.10 to celsius 235.61

要將溫度從華氏度轉換為攝氏度,有一個公式如下

T(°C) = (T(°F) - 32) × 5/9

其中,T(°C) 為攝氏溫度,T(°F) 為華氏溫度

以下使用的途徑如下

  • 將溫度輸入一個浮點數變數,假設為華氏度
  • 應用該公式將溫度轉換為攝氏度
  • 列印攝氏度

演算法

Start
Step 1-> Declare function to convert Fahrenheit to Celsius
   float convert(float fahrenheit)
      declare float Celsius
      Set celsius = (fahrenheit - 32) * 5 / 9
      return Celsius
step 2-> In main()
   declare and set float fahrenheit = 132.00
   Call convert(fahrenheit)
Stop

例如

即時演示

#include <stdio.h>
//convert fahrenheit to celsius
float convert(float fahrenheit) {
   float celsius;
   celsius = (fahrenheit - 32) * 5 / 9;
   return celsius;
}
int main() {
   float fahrenheit = 132.00;
   printf("after converting fahrenheit %.2f to celsius %.2f ",fahrenheit,convert(fahrenheit));
   return 0;
}

輸出

如果我們執行以上的程式碼,它將產生以下輸出

after converting fahrenheit 132.00 to celsius 55.56

更新於:2019-10-18

813 瀏覽量

開啟您的職業

完成本課程將獲得認證

開始
廣告