C++ Program to swap two numbers without using 3rd variable [DEVCPP/GCC]


//Program to swap two numbers without using 3rd variable

#include<iostream>

using namespace std;

int main()
{
int a,b;

cout<<"ENTER THE VALUE OF A:";
cin>>a;
cout<<"ENTER THE VALUE OF B:";
cin>>b;
cout<<"BEFORE SWAPPING:"<<endl<<"A="<<a<<" "<<"B="<<b<<endl;

a=a+b;
b=a-b;
a=a-b;
cout<<"AFTER SWAPPING:"<<endl<<"A="<<a<<" "<<"B="<<b<<endl;

return 0;
}



Share this

Related Posts

FIND US ON FACEBOOK!