// SwapTwoNumber.cpp : 定义控制台应用程序的入口点。
//通过此实例实现两个数的交换
#include "stdafx.h"
#include <process.h>
#include <iostream>
using namespace std;
void SwapMethod1(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void SwapMethod2(int &a,int &b)
{
a=a+b;
b=a-b;
a=a-b;
}
void SwapMethod3(int &a,int &b)
{
a=a^b;
b=a^b;
a=a^b;
}
int _tmain(int argc,_TCHAR* argv[])
{
cout<<"-------交换算法测试案例-------------"<<endl;
cout<<"请输入两个数(空格间隔):";
int a,b;
cin>>a>>b;
SwapMethod1(a,b);
cout<<"a="<<a<<" b="<<b<<endl;
SwapMethod2(a,b);
cout<<"a="<<a<<" b="<<b<<endl;
SwapMethod3(a,b);
cout<<"a="<<a<<" b="<<b<<endl;
system("pause");
return 0;
}