用cpp语言写出以下程序给定一个华氏温度 F ,本题要求编写程序,计算对应的摄氏温度 C 。计算公式: C =5x( F -32)/9。题目保证输入与输出均在整型范围内。 输入格式: 输入在一行中给出一个华氏温度。输出格式: 在一行中按照格式" Celsius = C "输出对应的摄氏温度 C 的整数值。
时间: 2023-04-04 11:01:43 浏览: 65
华氏温度转摄氏温度的程序如下:
#include <iostream>
using namespace std;
int main() {
int f;
cin >> f;
int c = 5 * (f - 32) / 9;
cout << "Celsius = " << c << endl;
return ;
}
输入一个华氏温度,程序会计算出对应的摄氏温度并输出。
相关问题
编写温度换算程序,输入摄氏温度C,输出对应华氏温度F c➕➕代码
以下是一个简单的 C++ 温度换算程序,可以将摄氏温度转换为华氏温度:
```cpp
#include <iostream>
using namespace std;
int main() {
double celsius, fahrenheit;
cout << "请输入摄氏温度:";
cin >> celsius;
fahrenheit = celsius * 1.8 + 32;
cout << "华氏温度为:" << fahrenheit << endl;
return 0;
}
```
在这个程序中,我们首先定义了两个变量 `celsius` 和 `fahrenheit`,分别用于存储输入的摄氏温度和计算得到的华氏温度。然后,我们使用 `cout` 和 `cin` 分别输出和输入温度值。最后,我们根据摄氏温度的公式将其转换为华氏温度,并输出结果。
希望这个程序能够帮到你!
编写摄氏温度、华氏温度转换程序。要求:从键盘输入一个摄氏温度,屏幕就显示对 应的华氏温度,输出取两位小数
好的,下面是一个使用C++编写的摄氏温度和华氏温度转换程序:
```cpp
#include <iostream>
#include <iomanip>
int main() {
float celsius, fahrenheit;
std::cout << "请输入摄氏温度:";
std::cin >> celsius;
fahrenheit = (celsius * 9 / 5) + 32;
std::cout << "华氏温度为:" << std::fixed << std::setprecision(2) << fahrenheit << std::endl;
return 0;
}
```
这段代码首先从键盘输入一个摄氏温度,然后使用公式 `(摄氏温度 * 9 / 5) + 32` 将其转换为华氏温度。最后,使用 `std::fixed` 和 `std::setprecision(2)` 来设置输出的小数点精度为两位小数。
希望对你有所帮助!如果还有其他问题,请随时提问。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)