华氏度转摄氏度的C语言代码
时间: 2024-05-24 11:12:29 浏览: 14
以下是华氏度转摄氏度的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;
}
代码解析:
1. 首先,我们需要声明两个变量,一个用于存储输入的华氏度,另一个用于存储转换后的摄氏度。
2. 然后,我们通过printf语句提示用户输入华氏度,并通过scanf函数将其存储到变量fahrenheit中。
3. 接下来,我们使用公式(fahrenheit - 32) * 5 / 9将华氏度转换为摄氏度,并将结果存储到变量celsius中。
4. 最后,我们通过printf语句输出转换后的摄氏度。
注意:本代码中使用了%.2f格式符对浮点数进行格式化输出,保留两位小数。
相关问题
将华氏度转换为摄氏度c语言
下面是将华氏度转换为摄氏度的 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语言代码,用于将摄氏度转换为华氏度:
```c
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("请输入摄氏度:");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("华氏度为:%.2f\n", fahrenheit);
return 0;
}
```
这段代码首先要求用户输入摄氏度,然后使用公式 `(摄氏度 * 9 / 5) + 32` 将其转换为华氏度,并将结果打印出来。
相关推荐
![](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)