What is Swapping:
Example-
Two variable are a=10,b=20
After Swapping:
a=20,b=10
program:
#include< iostream>
using namespace std;
int main()
{
int a,b,temp;
cout<<"Enter two numbersn";
cin>>a>>b;
cout<<"Before swapping:n";
cout<<"a and b is: "<< a<<" "<< b<< endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"After swapping:n";
cout<<"a and b is: "<< a<<" "<< b;
return 0;
}
Enter two numbers
10 20
Before swapping
a and b is: 10 20
After Swapping
a and b is: 20 10