C语言程序将华氏度转换为摄氏度

如何编写C语言程序将华氏度转换为摄氏度,并附带示例。从华氏度转换为摄氏度的数学公式是:摄氏度 = (5 / 9) * (华氏度 – 32)。例如,220摄氏度 c 等于 428 华氏度 f。而200华氏度 f 转换为摄氏度 c 等于 93.3333。

C语言程序将华氏度转换为摄氏度

此华氏度转摄氏度程序允许用户输入华氏度的温度值。接下来,程序使用F转C公式将华氏度转换为摄氏度。

#include <stdio.h>
 
int main()
{
    float celsius, fahrenheit;
 
    printf("Please Enter the temperature in Fahrenheit: \n");
    scanf("%f", &fahrenheit);
 
    // Convert the temperature from f to c formula
    celsius = (fahrenheit - 32) * 5 / 9;
    //celsius = 5 *(fahrenheit - 32) / 9;
    //celsius =(fahrenheit-32) * 0.55556; 

    printf("\n %.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius);
 
    return 0;
}
C Program to convert Fahrenheit to Celsius 1

我们都知道水的沸点是212华氏度。水的冰点是32华氏度。分析此程序,用于将华氏度转换为摄氏度的示例。

前两个语句要求用户输入温度值。接下来,scanf语句会将用户输入的值赋给一个已声明的变量。

我们可以使用上面代码中指定的以下任何公式将温度从华氏度转换为摄氏度。

celsius = (Fahrenheit – 32) * 5 / 9

最后一个C编程的printf语句将打印输出。

printf("\n %.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius);

我将向您展示32华氏度的摄氏值。类似地,100华氏度转换为摄氏度是37.7778。接下来,200华氏度转换为摄氏度是93.3333。

Please Enter the temperature in Fahrenheit: 
32

 32.00 Fahrenheit = 0.00 Celsius


Please Enter the temperature in Fahrenheit: 
100

 100.00 Fahrenheit = 37.7778 Celsius

Please Enter the temperature in Fahrenheit: 
200

 200.00 Fahrenheit = 93.3333 Celsius