三个数找最大值并按顺序输出的源代码
时间: 2023-06-04 12:07:06 浏览: 47
以下是一个可以找出三个数的最大值并按顺序输出的源代码:
```c++
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "请输入三个数字:" << endl;
cin >> a >> b >> c;
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
cout << "最大值为:" << max << endl;
cout << "按顺序输出为:" << endl;
if (a >= b && a >= c) {
cout << a << " ";
if (b >= c) {
cout << b << " " << c << endl;
} else {
cout << c << " " << b << endl;
}
} else if (b >= a && b >= c) {
cout << b << " ";
if (a >= c) {
cout << a << " " << c << endl;
} else {
cout << c << " " << a << endl;
}
} else if (c >= a && c >= b) {
cout << c << " ";
if (a >= b) {
cout << a << " " << b << endl;
} else {
cout << b << " " << a << endl;
}
}
return 0;
}
```
希望能够满足您关于求最大值的问题。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![torrent](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)