用c语言写输入华氏温度求摄氏度的代码
时间: 2023-05-25 12:05:22 浏览: 52
```
#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;
}
```
相关问题
用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;
}
```
输入华氏温度或摄氏温度后,程序会自动计算并输出另一种温度的值。
注意:本程序只是一个简单的示例,实际应用中可能需要考虑更多的情况,比如输入错误的温度值等。
写一个华氏温度转换成摄氏温度的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;
}
```
代码解释:
1. 定义两个浮点型变量 `fahrenheit` 和 `celsius` 分别用于存储华氏温度和摄氏温度。
2. 使用 `printf` 函数提示用户输入华氏温度,并使用 `scanf` 函数获取用户输入的华氏温度。
3. 使用公式 `(fahrenheit - 32) * 5 / 9` 将华氏温度转换为摄氏温度,并将结果赋值给 `celsius` 变量。
4. 使用 `printf` 函数输出转换后的摄氏温度,保留两位小数。
5. 返回 0 表示程序正常结束。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)