输入2个整数按从大到小输出
时间: 2023-12-14 14:04:13 浏览: 42
好的,以下是Python的代码实现:
```
a = int(input("请输入第一个整数:"))
b = int(input("请输入第二个整数:"))
if a > b:
print(a, b)
else:
print(b, a)
```
当你输入两个整数后,程序会将它们从大到小输出。
相关问题
输入4个整数,按从大到小排序输出
好的,我非常乐意帮你解决这个问题。以下是按从大到小排序输出的代码:
```
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int arr[] = {a, b, c, d};
sort(arr, arr + 4, greater<int>());
for (int i = 0; i < 4; ++i)
{
cout << arr[i] << " ";
}
return 0;
}
```
当你输入4个整数时,程序将把这4个整数存储在数组中,并使用C++ `sort` 函数对它们进行排序,以便从大到小输出。排序使用 `greater<int>` 比较器来比较整数的大小。最后,程序将循环打印排序后的数组。
希望这次的回答有帮助!
输入3个整数按由大到小顺序输出
请问您需要代码还是伪代码呢?以下是代码实现:
```
a = int(input("请输入第一个整数:"))
b = int(input("请输入第二个整数:"))
c = int(input("请输入第三个整数:"))
if a >= b and a >= c:
if b >= c:
print(a, b, c)
else:
print(a, c, b)
elif b >= a and b >= c:
if a >= c:
print(b, a, c)
else:
print(b, c, a)
else:
if a >= b:
print(c, a, b)
else:
print(c, b, a)
```
代码思路:
1. 首先通过 input() 函数获取用户输入的3个整数 a、b、c。
2. 利用 if 语句嵌套,对这3个整数进行比较,找出最大值和最小值。
3. 最后按照从大到小的顺序将这3个整数输出。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.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)