#include <stdio.h>
void sortAndPrint(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;
}
printf("%d %d %d\n", a, b, c);
}
int main() {
int num1, num2, num3;
printf("Enter three numbers:\n");
scanf("%d %d %d", &num1, &num2, &num3);
printf("Sorted numbers: ");
sortAndPrint(num1, num2, num3);
return 0;
}
说明:
- 定义一个函数
sortAndPrint
来对三个数进行排序并按升序输出。 - 在
main
函数中读取三个数并调用sortAndPrint
函数输出排序结果。