c语言计算摄氏温度程序
时间: 2023-03-15 08:51:14 浏览: 211
在 C 语言中,可以使用以下程序来计算摄氏温度:
#include <stdio.h>
int main()
{
float fahrenheit, celsius;
printf("输入摄氏温度:");
scanf("%f", &celsius); // 计算华氏温度
fahrenheit = (celsius * 9/5) + 32; printf("华氏温度为:%.2f", fahrenheit); return 0;
}
相关问题
用C语言编写华氏温度转换为摄氏温度的程序。
好的,下面是用C语言编写的华氏温度转换为摄氏温度的程序:
```c
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f 华氏度 = %.2f 摄氏度", fahrenheit, celsius);
return 0;
}
```
需要注意的是,celsius和fahrenheit都是浮点型变量,用来保存温度的值。其中,公式 `(fahrenheit - 32) * 5 / 9` 是华氏温度转换为摄氏温度的标准公式。程序中,使用 `scanf` 函数获取用户输入的华氏温度,然后计算出摄氏温度并打印出来。
c语言华氏温度转化成摄氏温度
以下是一个简单的C语言程序,将华氏温度转换为摄氏温度:
```
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f Fahrenheit is %.2f Celsius\n", fahrenheit, celsius);
return 0;
}
```
程序首先提示用户输入华氏温度,然后使用scanf()函数将输入存储在变量fahrenheit中。接着,程序使用公式`(F - 32) * 5 / 9`将华氏温度转换为摄氏温度,并将结果存储在变量celsius中。最后,程序使用printf()函数打印转换后的温度值。
注意:在计算摄氏温度时,我们使用了浮点数,因为结果可能是小数。另外,我们使用了“%.2f”格式说明符,以保留结果值的小数点后两位。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)