c语言使用double华氏温度转摄氏温度
时间: 2024-01-30 09:04:04 浏览: 29
使用C语言将华氏温度转换为摄氏温度可以使用以下公式:
C = (F - 32) * 5 / 9
其中,C表示摄氏温度,F表示华氏温度。
以下是一个示例代码:
```c
#include <stdio.h>
int main() {
double fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%lf", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f℉ = %.2f℃", fahrenheit, celsius);
return 0;
}
```
在运行程序时,输入华氏温度即可得到相应的摄氏温度。
相关问题
c语言double求温度转换
摄氏温度与华氏温度的转换公式如下:
华氏温度 = 1.8 * 摄氏温度 + 32
摄氏温度 = (华氏温度 - 32) / 1.8
在C语言中,可以使用double类型来存储温度值,如下是一个摄氏温度转换为华氏温度的示例代码:
```c
#include <stdio.h>
int main()
{
double celsius, fahrenheit;
printf("请输入摄氏温度:");
scanf("%lf", &celsius);
fahrenheit = 1.8 * celsius + 32;
printf("转换后的华氏温度为:%.2lf\n", fahrenheit);
return 0;
}
```
如果要进行华氏温度转换为摄氏温度,可以使用下面的代码:
```c
#include <stdio.h>
int main()
{
double celsius, fahrenheit;
printf("请输入华氏温度:");
scanf("%lf", &fahrenheit);
celsius = (fahrenheit - 32) / 1.8;
printf("转换后的摄氏温度为:%.2lf\n", celsius);
return 0;
}
```
华氏度和摄氏度相互转换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;
}
```
这个程序首先要求用户输入华氏温度,然后根据转换公式将其转换为摄氏温度,并将结果保留两位小数进行输出。
相关推荐
![](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)