变量之间交换数据(不用第三变量)
编程之中却有诸多美妙之处。
#include <STDIO.H>
int main()
{
int a,b;
printf("input the value of a and b:\n");
scanf("%d%d",&a,&b);
printf("before exchange:");
printf("a=%d\tb=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("after the 1st:");
printf("a=%d\tb=%d\n",a,b);
a=a^b;
b=b^a;
a=a^b;
printf("after the 2nd:");
printf("a=%d\tb=%d\n",a,b);
return 0;
}
posted on 2012-07-24 21:37 xingma0910 阅读(411) 评论(1) 编辑 收藏 举报