Problem C: 利用函数从大到小输出2个数
Description
我们知道利用函数交换2个数,如果采用值传递是实现不了的,那么怎么办呢?我们不是刚学过指针吧?对,就用指针来做。
Input
多组测试数据。每组测试数据输入2个整数。
Output
对于每组测试数据,从大到小输出数
Sample Input
2 3
4 5
Sample Output
3 2
5 4
HINT
#include
void swap(int *p1,int *p2)
{
…
}
int main()
{ int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
…
printf("%d %d\n",a,b);
}
}
#include<stdio.h>
void swap(int *a,int *b);
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){
if(a<b)
swap(&a,&b);
printf("%d %d\n",a,b);
}
return 0;
}
void swap(int *a,int *b)
{
int s;
s=*b;
*b=*a;
*a=s;
}