交换两个数的值

///////////////////////////////////////////////////////////
// Copyright (c) 2013, ShangHai XXX Inc.
//
// FileName: exchange.cpp
//
// Description:
//
// Created: Mon Sep 23 15:40:13 2013
// Revision: Revision: 1.0
// Compiler: g++
//
///////////////////////////////////////////////////////////
#include <iostream>

using namespace std;

int main()
{
int n = 1;
int m = 5;
cout<<"before exchange\t n = "<<n<<" m = "<<m<<endl;

n = n + m;
m = n - m;
n = n - m;
cout<<"after exchange\t n = "<<n<<" m = "<<m<<endl;

n = n ^ m;
m = n ^ m;
n = n ^ m;
cout<<"after exchange\t n = "<<n<<" m = "<<m<<endl;

}

posted @ 2013-09-23 16:44  艾丽娅的猫  阅读(166)  评论(0编辑  收藏  举报