Problem D: 指针:调用自定义交换函数,完成三个数整从小到大排列
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 19449 Solved: 12856
Description
调用自定义交换函数swap(int *p1, int *p2),完成三个整数从小到大排列
Input
多组测试数据,每组输入三个任意整数
Output
输出从小到大排列的三个数
Sample Input
9 2 7
0 -2 12
8 3 1
Sample Output
2 7 9
-2 0 12
1 3 8
#include <stdio.h>
void swap(int *p1, int *p2);
int main()
{
int a,b,c;
while (scanf("%d%d%d",&a,&b,&c) != EOF)
{
swap(&a,&b);
swap(&b,&c);
swap(&a,&b);
printf("%d %d %d\n",a,b,c);
}
return 0;
}
void swap(int *p1, int *p2)
{
int t;
if (*p1 > *p2)
{
t = *p1;
*p1 = *p2;
*p2 = t;
}
}