输入3个数a,b,c,按从小到大的顺序输出
时间: 2024-02-21 13:02:26 浏览: 19
好的,可以这样实现:
```python
a = int(input("请输入第一个数:"))
b = int(input("请输入第二个数:"))
c = int(input("请输入第三个数:"))
if a <= b <= c:
print(a, b, c)
elif a <= c <= b:
print(a, c, b)
elif b <= a <= c:
print(b, a, c)
elif b <= c <= a:
print(b, c, a)
elif c <= a <= b:
print(c, a, b)
else:
print(c, b, a)
```
你可以输入三个数字,它会自动输出从小到大排列的结果。
相关问题
c语言输入三个整数a、b、c,按从小到大的顺序输出
可以使用冒泡排序的思想来实现这个要求:
```c
#include <stdio.h>
int main()
{
int a, b, c;
int 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;
}
```
这个程序中,我们先通过 `scanf` 函数获取用户输入的三个整数。然后使用冒泡排序的思想,将三个数按从小到大的顺序排列。最后将排好序的结果输出即可。
输入三个数a,b,c,从小到大的顺序输出
好的,这是一个简单的排序问题,我可以为您提供代码示例,您可以参考一下:
```
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (a > c) {
int temp = a;
a = c;
c = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
cout << a << " " << b << " " << c << endl;
return 0;
}
```
您可以将三个数输入,程序会自动将它们从小到大排序并输出。希望能对您有帮助。
相关推荐
![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)