在摄氏温度为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 将摄氏温度转换为华氏温度 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
#include <stdio.h>
//将摄氏温度转换为华氏温度
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
#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