C++ 中攝氏度轉換為華氏度的程式


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

比如

Input 1-: 100.00
   Output -: 212.00
Input 2-: -40
   Output-: -40

從攝氏度轉換為華氏度的溫度有以下公式

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

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

下面使用的演算法如下

  • 輸入浮點變數中的溫度,記為攝氏度
  • 應用公式將溫度轉換為華氏度
  • 列印華氏度

演算法

Start
Step 1 -> Declare a function to convert Celsius to Fahrenheit
   void cal(float cel)
      use formula float fahr = (cel * 9 / 5) + 32
      print cel fahr
Step 2 -> In main()
   Declare variable as float Celsius
   Call function cal(Celsius)
Stop

使用 C 語言

比如

 現場演示

#include <stdio.h>
//convert Celsius to fahrenheit
void cal(float cel){
   float fahr = (cel * 9 / 5) + 32;
   printf("%.2f Celsius = %.2f Fahrenheit", cel, fahr);
}
int main(){
   float Celsius=100.00;
   cal(Celsius);
   return 0;
}

輸出

100.00 Celsius = 212.00 Fahrenheit

使用 C++ 語言

比如

 現場演示

#include <bits/stdc++.h>
using namespace std;
float cel(float n){
   return ((n * 9.0 / 5.0) + 32.0);
}
int main(){
   float n = 20.0;
   cout << cel(n);
   return 0;
}

輸出

68

更新時間: 2019 年 9 月 20 日

698 次瀏覽

開啟您的 職業

完成課程以獲得認證

立即開始
廣告
© . All rights reserved.