The easier way:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d\nb=%d\n",a,b);
system("pause");
return 0;
}
The solution is easy to deal with,otherwise it exist some weak points.
(数据容易发生溢出)
The effective way:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
a=a^b;
b=a^b;
a=a^b;
printf("a=%d\nb=%d\n",a,b);
system("pause");
return 0;
}
本文出自 “liveyoung” 博客,转载请与作者联系!