下面的程序是从键盘输入三个整数按从小到大的顺序输出。我需要代码
时间: 2023-03-30 18:02:04 浏览: 72
请看下面的代码:
#include <stdio.h>
int main()
{
int a, b, c, t;
scanf("%d%d%d", &a, &b, &c);
if (a > b) { t = a; a = b; b = t; }
if (a > c) { t = a; a = c; c = t; }
if (b > c) { t = b; b = c; c = t; }
printf("%d %d %d\n", a, b, c);
return ;
}
相关问题
下面的程序是从键盘输入三个整数 按从小到大的顺序输出。
以下是使用 Python 语言编写的程序,可以实现从键盘输入三个整数,按从小到大的顺序输出:
```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)
```
该程序首先使用 `input()` 函数从键盘输入三个整数,然后使用 if 语句判断三个整数的大小关系,并按照从小到大的顺序输出。
下面的程序是从键盘输入三个整数按从小到大的顺序输出。
输入:
```
a = int(input())
b = int(input())
c = int(input())
```
输出:
```
if a > b:
a, b = b, a
if b > c:
b, c = c, b
if a > b:
a, b = b, a
print(a, b, c)
```