# topics
Swaps the values of two variables without using a new variable.
# ideas
method One: use the Add and subtract operation to exchange the values of two variables.
A = A+b
B = a A
A = A-B
method Two: exchange values of two variables using XOR operation
A = A^b
B = A^b
A = A^b
# code
#include <iostream>using namespace std;void fun1 (int m,int n) {cout<<"method One, exchange two variables based on addition and subtraction"<<Endl; M= m +N; N= M-N; M= M-N; cout<<m<<" "<<n<<Endl;} void fun2 (int m,int n) {cout<<"method Two, exchange two variables based on XOR operation"<<Endl; M= m^N; N= m^N; M= m^N; cout<<m<<" "<<n<<Endl;} int main () {int M= 10; int n= 20; cout<<"Original Value"<<Endl; cout<<m<<" "<<n<<Endl; FUN1 (M,n); Fun2 (M,n); return0;}
"Sword means offer" does not use the new variable, exchange the value of two variables, C + + implementation