三个整数从大到小排序c语言
时间: 2023-11-07 18:05:38 浏览: 147
c语言 整数链表排序
4星 · 用户满意度95%
一个实现三个整数从大到小排序的C语言方法是使用三个变量来存储这三个整数,并使用条件语句比较它们的大小,然后将它们按顺序赋值给另外三个变量。最后,输出这三个变量的值即可。
```c
int main() {
int a, b, c, first, second, third;
printf("请输入三个整数:");
scanf("%d%d%d", &a, &b, &c);
if (a >= b && a >= c) {
first = a;
if (b >= c) {
second = b;
third = c;
} else {
second = c;
third = b;
}
} else if (b >= a && b >= c) {
first = b;
if (a >= c) {
second = a;
third = c;
} else {
second = c;
third = a;
}
} else {
first = c;
if (a >= b) {
second = a;
third = b;
} else {
second = b;
third = a;
}
}
printf("从大到小排序的结果为: %d, %d, %d\n", first, second, third);
}
```
阅读全文