将华氏度转换为摄氏度c语言
时间: 2023-05-23 18:03:56 浏览: 53
下面是将华氏度转换为摄氏度的 c 代码:
```c
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入温度(华氏度):");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("转换后的温度为 %.2f 摄氏度\n", celsius);
return 0;
}
```
输入华氏度,然后通过公式转换为摄氏度。
相关问题
c语言华氏度转换成摄氏度代码
C语言华氏度转换成摄氏度的代码如下:
#include <stdio.h>
int main(){
float fahrenheit, celsius;
printf("请输入华氏度: ");
scanf("%f", &fahrenheit); // 从控制台输入华氏度值
celsius = (fahrenheit - 32) * 5 / 9; // 摄氏度转换公式
printf("%.2f 华氏度 = %.2f 摄氏度\n", fahrenheit, celsius); // 输出结果
return 0;
}
用户可以在控制台输入要转换的华氏度值,程序会自动使用转换公式把华氏度转换成摄氏度,并打印出结果。该代码还使用了 %.2f 格式化输出,这样输出的结果会保留两位小数,更加清晰明了。
c语言将华氏温度转换为摄氏温度
华氏温度和摄氏温度之间的转换公式为:`C = (F - 32) / 1.8`,其中 `C` 表示摄氏温度,`F` 表示华氏温度。因此,要将华氏温度转换为摄氏温度,只需要按照公式进行计算即可。示例代码如下:
```c
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) / 1.8; // 摄氏温度的计算公式
printf("华氏温度 %.2f 度等于摄氏温度 %.2f 度\n", fahrenheit, celsius);
return 0;
}
```
在上述代码中,我们使用了浮点数类型 `float` 来存储华氏温度和摄氏温度,同时使用了 `%.2f` 格式化字符串来保留两位小数输出温度值。
希望能够帮到您!
相关推荐
![](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)