华氏度和摄氏度相互转换C语言
时间: 2024-06-14 08:04:41 浏览: 13
以下是一个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语言华氏度转换成摄氏度的代码如下:
#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语言实现摄氏度与华氏度的相互转换
可以使用以下代码实现摄氏度与华氏度的相互转换:
#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 ;
}
相关推荐
![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)