从键盘输入三个数,按照从大到小的顺序输出三个数
时间: 2023-04-19 08:04:22 浏览: 62
可以使用以下代码实现:
```
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)
```
运行程序后,会提示用户输入三个数,然后根据大小关系输出这三个数。
相关问题
c语言从键盘输入三个数,按从大到小的顺序输出
可以使用冒泡排序算法来实现这个功能,具体代码如下:
```c
#include <stdio.h>
int main() {
int a, b, c, temp;
printf("请输入三个数:\n");
scanf("%d %d %d", &a, &b, &c);
if (a < b) {
temp = a;
a = b;
b = temp;
}
if (a < c) {
temp = a;
a = c;
c = temp;
}
if (b < c) {
temp = b;
b = c;
c = temp;
}
printf("从大到小的顺序是:%d %d %d\n", a, b, c);
return 0;
}
```
这个程序会从键盘输入三个数,然后使用三次 if 语句来比较它们的大小,最终输出从大到小的顺序。
从键盘输入三个整数按照由小到大的顺序输出
```python
a = int(input("请输入第一个整数:"))
b = int(input("请输入第二个整数:"))
c = int(input("请输入第三个整数:"))
# 冒泡排序
if a > b:
a, b = b, a
if a > c:
a, c = c, a
if b > c:
b, c = c, b
print("从小到大的顺序为:", a, b, c)
```
示例输出:
```
请输入第一个整数:3
请输入第二个整数:1
请输入第三个整数:7
从小到大的顺序为: 1 3 7
```
相关推荐
![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)