输入3个数a,b,c,要求按由小到大的顺序输出。
时间: 2023-04-18 08:00:27 浏览: 81
可以使用以下代码实现:
a = int(input("请输入第一个数:"))
b = int(input("请输入第二个数:"))
c = int(input("请输入第三个数:"))
# 使用列表存储三个数
lst = [a, b, c]
# 对列表进行排序
lst.sort()
# 输出排序后的结果
print("由小到大的顺序输出:", lst)
相关问题
输入三个数a.b.c,要求按由小到大的顺序输出
可以使用以下代码实现:
```python
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)
```
这段代码会先读入三个数,然后使用 if 语句判断它们的大小关系,最后按照从小到大的顺序输出。
用c语言程序输入三个数a.b.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 语句来比较它们的大小,最终输出排序后的结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)