用c语言实现摄氏度与华氏度的相互转换
时间: 2023-04-04 14:01:04 浏览: 112
可以使用以下代码实现摄氏度与华氏度的相互转换:
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("请输入摄氏度: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f 摄氏度 = %.2f 华氏度\n", celsius, fahrenheit);
printf("请输入华氏度: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f 华氏度 = %.2f 摄氏度\n", fahrenheit, celsius);
return ;
}
相关问题
华氏度和摄氏度相互转换C语言
以下是一个C语言的例子,用于将华氏度转换为摄氏度:
```c
#include <stdio.h>
int main() {
double f, c;
printf("请输入华氏温度\n℉=");
scanf("%lf", &f);
c = 5.0 / 9 * (f - 32);
printf("摄氏度\nc=%.2lf\n", c);
return 0;
}
```
这个程序首先要求用户输入华氏温度,然后根据转换公式将其转换为摄氏温度,并将结果保留两位小数进行输出。
用c语言实现:华氏温度与摄氏温度相互转换
以下是用 C 语言实现华氏温度与摄氏温度相互转换的代码:
```c
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("摄氏温度为:%.2f\n", celsius);
printf("请输入摄氏温度:");
scanf("%f", &celsius);
fahrenheit = celsius * 9 / 5 + 32;
printf("华氏温度为:%.2f\n", fahrenheit);
return 0;
}
```
输入华氏温度或摄氏温度后,程序会自动计算并输出另一种温度的值。
注意:本程序只是一个简单的示例,实际应用中可能需要考虑更多的情况,比如输入错误的温度值等。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)