给定两个整形变量的值,将两个值的内容进行交换

来源:互联网 发布:淘宝买了不评价 编辑:程序博客网 时间:2024/04/28 17:44

给定两个整形变量的值,将两个值的内容进行交换

方法一:

#include<stdio.h>
int main()
{
 int a=3,b=2,t;
 t=a;
 a=b;
 b=t;
 printf("%d%2.d\n",a,b);
return 0;
}

方法二:

#include<stdio.h>
int main()
{
 int a=3,b=2;
 a=a+b;
 b=a-b;
 a=a-b;
 printf("%d%2.d\n",a,b);
 return 0;
}


方法三:
#include<stdio.h>
int main()
{
 int a=3,b=2;
 a=a^b;
 b=b^a;
 a=a^b;
 printf("%d%2.d\n",a,b);
return 0;

}


阅读全文
0 0