用c++编一段代码,要求输入华氏温度,输出
时间: 2023-05-28 07:04:48 浏览: 62
对应的摄氏温度。
```c
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("摄氏温度为:%.2f\n", celsius);
return 0;
}
```
运行结果:
```
请输入华氏温度:68
摄氏温度为:20.00
```
相关问题
用c++编一段代码,要求输入大写字母,然后输出小写字母
```c
#include <stdio.h>
int main() {
char c;
printf("请输入一个大写字母:");
scanf("%c", &c);
if (c >= 'A' && c <= 'Z') {
c = c + 32;
printf("对应的小写字母是:%c\n", c);
} else {
printf("输入有误!\n");
}
return 0;
}
```
输入华氏温度F,计算输出对应的摄氏温度。这段代码用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 ;
}
```
感谢您的提问!
相关推荐
![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)