输入三个数a,b,c,从小到大的顺序输出
时间: 2023-09-17 22:07:25 浏览: 116
好的,这是一个简单的排序问题,我可以为您提供代码示例,您可以参考一下:
```
#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;
}
```
您可以将三个数输入,程序会自动将它们从小到大排序并输出。希望能对您有帮助。
相关问题
c语言输入三个数输出从小到大的顺序
可以的,下面是代码:
```c
#include <stdio.h>
int main()
{
int a, b, c;
printf("请输入三个整数:");
scanf("%d%d%d", &a, &b, &c);
if (a <= b && a <= c) {
printf("%d ", a);
if (b <= c) printf("%d %d", b, c);
else printf("%d %d", c, b);
}
else if (b <= a && b <= c) {
printf("%d ", b);
if (a <= c) printf("%d %d", a, c);
else printf("%d %d", c, a);
}
else {
printf("%d ", c);
if (a <= b) printf("%d %d", a, b);
else printf("%d %d", b, a);
}
return 0;
}
```
输入三个数,会按从小到大的顺序输出。
用C语言输出输入三个数,要求从小到大的顺序输出
可以使用条件语句和循环语句来实现从小到大的排序。
以下是一种实现方式:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:");
scanf("%d %d %d", &a, &b, &c);
if (a > b) { // 如果a大于b,将它们交换
int temp = a;
a = b;
b = temp;
}
if (a > c) { // 如果a大于c,将它们交换
int temp = a;
a = c;
c = temp;
}
if (b > c) { // 如果b大于c,将它们交换
int temp = b;
b = c;
c = temp;
}
printf("从小到大的顺序为:%d %d %d\n", a, b, c);
return 0;
}
```
输出示例:
```
请输入三个整数:3 1 5
从小到大的顺序为:1 3 5
```