在华氏温度为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 转换华氏到摄氏
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
//转换华氏到摄氏
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