用C++编写一个代码,输入3个整数a、b、c,按从大到小的顺序输出。要求通过指针实现
时间: 2024-04-29 14:21:13 浏览: 77
python 输入3个数a,b,c,按大小顺序输出(示例)
```c
#include <stdio.h>
void sort(int *a, int *b, int *c);
int main() {
int a, b, c;
printf("请输入3个整数:\n");
scanf("%d %d %d", &a, &b, &c);
sort(&a, &b, &c);
printf("%d %d %d", a, b, c);
return 0;
}
void sort(int *a, int *b, int *c) {
int tmp;
if (*a < *b) {
tmp = *a;
*a = *b;
*b = tmp;
}
if (*a < *c) {
tmp = *a;
*a = *c;
*c = tmp;
}
if (*b < *c) {
tmp = *b;
*b = *c;
*c = tmp;
}
}
```
阅读全文