c++写一个摄氏度转华氏度
时间: 2023-03-23 13:01:59 浏览: 141
您好,以下是将摄氏度转换为华氏度的C语言代码:
```
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
printf("请输入摄氏度:");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f 摄氏度 = %.2f 华氏度", celsius, fahrenheit);
return 0;
}
```
希望能对您有所帮助。
相关问题
c++华氏度和摄氏度相互转换
好的,我可以为你提供C++代码来实现华氏度和摄氏度的相互转换。以下是示例代码:
```c++
#include <iostream>
using namespace std;
int main() {
double fahrenheit, celsius;
int choice;
cout << "请选择转换类型:\n";
cout << "1. 摄氏度转华氏度\n";
cout << "2. 华氏度转摄氏度\n";
cin >> choice;
switch (choice) {
case 1:
cout << "请输入摄氏度:\n";
cin >> celsius;
fahrenheit = (celsius * 1.8) + 32;
cout << "华氏度为:" << fahrenheit << endl;
break;
case 2:
cout << "请输入华氏度:\n";
cin >> fahrenheit;
celsius = (fahrenheit - 32) / 1.8;
cout << "摄氏度为:" << celsius << endl;
break;
default:
cout << "输入有误,请重新选择!" << endl;
break;
}
return 0;
}
```
这段代码首先让用户选择转换类型,然后根据用户的选择,分别进行摄氏度转华氏度或者华氏度转摄氏度的计算,并输出结果。希望这段代码能够帮到你!
C++华氏度和摄氏度相互转换
好的,我可以为你提供C++代码来实现华氏度和摄氏度的相互转换。以下是示例代码:
```c++
#include <iostream>
using namespace std;
int main() {
double fahrenheit, celsius;
int choice;
cout << "请选择转换类型:\n";
cout << "1. 摄氏度转华氏度\n";
cout << "2. 华氏度转摄氏度\n";
cin >> choice;
switch (choice) {
case 1:
cout << "请输入摄氏度:\n";
cin >> celsius;
fahrenheit = (celsius * 1.8) + 32;
cout << "华氏度为:" << fahrenheit << endl;
break;
case 2:
cout << "请输入华氏度:\n";
cin >> fahrenheit;
celsius = (fahrenheit - 32) / 1.8;
cout << "摄氏度为:" << celsius << endl;
break;
default:
cout << "输入有误,请重新选择!" << endl;
break;
}
return 0;
}
```
这段代码首先让用户选择转换类型,然后根据用户的选择,分别进行摄氏度转华氏度或者华氏度转摄氏度的计算,并输出结果。希望这段代码能够帮到你!
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.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)