用C++实现对 3 个变量按由小到大顺序排序用不带默认参数的函数实现的代码
时间: 2024-05-10 11:20:02 浏览: 77
```
#include <stdio.h>
void sort(int a, int b, int c);
int main() {
int x = 3, y = 2, z = 1;
sort(x, y, z);
printf("%d %d %d\n", x, y, z);
return 0;
}
void sort(int a, int b, int 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;
}
}
```
阅读全文