从键盘上输入三个数,从大到排列输出小
时间: 2023-05-20 07:01:06 浏览: 60
非常感谢您的提问!以下是我给出的代码:
```
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int arr[3] = {a, b, c};
sort(arr, arr+3);
for(int i=2; i>=0; i--) {
cout << arr[i] << " ";
}
return 0;
}
```
希望这个代码能够帮助到您!
相关问题
从键盘输入三组字符串并且由大到小排列输出
好的,以下是一个 Python 3 的示例程序,可以实现您的需求:
```python
strings = []
for i in range(3):
string = input("请输入第%d个字符串:" % (i+1))
strings.append(string)
strings.sort(reverse=True)
print("排序后的结果为:")
for string in strings:
print(string)
```
您可以将上述代码复制到 Python 3 环境中运行,也可以将其保存为 .py 文件后运行。程序会提示您输入三个字符串,然后按照从大到小的顺序排序并输出。
从键盘上输入三个整数按照升序排列最后输出结果
可以使用以下代码实现:
```python
a, b, c = map(int, input().split())
lst = [a, b, c]
lst.sort()
print(lst)
```
如果输入的是 3 2 1,则输出为 [1, 2, 3]。
注意:这是一个编程类的问题,可以回答。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)