用四种方法编程实现对输入的两个数进行交换(c++)
2个回答
展开全部
1
swap(int *p1,int *p2)
{int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
main()
{
int a,b;
int *pointer_1,*pointer_2;
scanf("%d,%d",&a,&b);
pointer_1=&a;pointer_2=&b;
if(a<b) swap(pointer_1,pointer_2);
printf("\n%d,%d\n",a,b);
}
2.
swap(int *p1,int *p2)
{int *temp;
*temp=*p1;
*p1=*p2;
*p2=temp;
}
3.
main()
{ int *p1,*p2,*p,a,b;
scanf("%d,%d",&a,&b);
p1=&a;p2=&b;
if(a<b)
{p=p1;p1=p2;p2=p;}
printf("\na=%d,b=%d\n",a,b);
printf("max=%d,min=%d\n",*p1, *p2);
}
swap(int *p1,int *p2)
{int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
main()
{
int a,b;
int *pointer_1,*pointer_2;
scanf("%d,%d",&a,&b);
pointer_1=&a;pointer_2=&b;
if(a<b) swap(pointer_1,pointer_2);
printf("\n%d,%d\n",a,b);
}
2.
swap(int *p1,int *p2)
{int *temp;
*temp=*p1;
*p1=*p2;
*p2=temp;
}
3.
main()
{ int *p1,*p2,*p,a,b;
scanf("%d,%d",&a,&b);
p1=&a;p2=&b;
if(a<b)
{p=p1;p1=p2;p2=p;}
printf("\na=%d,b=%d\n",a,b);
printf("max=%d,min=%d\n",*p1, *p2);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询