如何编写一个将摄氏度转换为华氏度的C程序,并附带示例。摄氏度到华氏度温度转换的公式是:华氏度 = (9/5) * 摄氏度) + 32
C程序将摄氏度转换为华氏度
这个将摄氏度转换为华氏度的程序允许用户输入摄氏度温度值。接下来,我们将用户指定的摄氏度转换为华氏度。
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
printf("Please Enter temperature in Celsius: \n");
scanf("%f", &celsius);
// Convert the temperature
fahrenheit = ((celsius * 9)/5) + 32;
// fahrenheit = ((9/5) * celsius) + 32;
// fahrenheit = ((1.8 * celsius) + 32;
printf("\n %.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}

在这个将摄氏度转换为华氏度的程序示例中,以下语句将提示用户输入摄氏度温度值。此C程序中的scanf语句将用户输入的值分配给已声明的变量Celsius。
printf("Please Enter temperature in Celsius: \n");
scanf("%f", &celsius);
我们可以使用以下任一公式将摄氏度转换为华氏度
华氏度 = ((摄氏度 * 9)/5) + 32
华氏度 = ((9/5) * 摄氏度) + 32 => ((1.8 * 摄氏度) + 32;
最后的C编程 printf语句将打印输出
printf("\n %.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
让我向您展示零摄氏度的华氏度值
Please Enter temperature in Celsius:
0
0.00 Celsius = 32.00 Fahrenheit
评论已关闭。