从键盘任意输入三个整数,按照由小到大的顺序输出
时间: 2024-05-09 22:19:32 浏览: 129
以下是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)
```
运行结果示例:
```
请输入第一个整数:5
请输入第二个整数:1
请输入第三个整数:9
从小到大排序后的结果为: 1 5 9
```
相关问题
用c语言实现从键盘任意输入三个整数,按照由小到大的顺序输出
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:");
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
if (a > c) {
int tmp = a;
a = c;
c = tmp;
}
if (b > c) {
int tmp = b;
b = c;
c = tmp;
}
printf("由小到大排序后的结果为:%d %d %d\n", a, b, c);
return 0;
}
```
运行结果:
```
请输入三个整数:5 2 8
由小到大排序后的结果为:2 5 8
```
从键盘输入任意三个整数,要求按照大小顺序输出这三个数
好的,您可以输入以下代码:
```
a, b, c = map(int, input("请输入三个整数,用空格隔开: ").split())
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)
```
这个程序会先让您从键盘输入三个整数,然后对它们进行排序,最后按照从小到大的顺序输出这三个数。请注意,以上代码仅供参考,您可以在实际使用时进行适当的调整和优化。
阅读全文
相关推荐












