A PLATFORM TO LEARN | CODE | ACHIEVE
" Programming is the real test of your creativity,its all about how you turn ideas into codes. "
Connect :
Code
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int num1,num2;
cout<<"ENTER TWO NUMBERS \n";
cin>>num1>>num2;
cout<<"FIRST NUMBER = "<<num1<<"\n";
cout<<"SECOND NUMBER = "<<num2<<"\n";
num1=num1^num2;
num2=num1^num2;
num1=num1^num2;
cout<<"SO,AFTER SWAPPING :\n";
cout<<"FIRST NUMBER = "<<num1<<"\n";
cout<<"SECOND NUMBER = "<<num2<<"\n";
return 0;
}
Output
ENTER TWO NUMBERS 10 20
FIRST NUMBER = 10
SECOND NUMBER = 20
SO,AFTER SWAPPING :
FIRST NUMBER = 20
SECOND NUMBER = 10
What we did - Our Approach
In this problem,we are supposed to swap the values of two numbers using xor operation.Swapping means interchanging of values among variables,swapping using xor operation takes place in three processes :
Let us assume that num1=20 num2=10 so,
See this code in :
Also see :
Participate in our MONTHLY CHALLENGE,and get a chance to get listed on our site and win the TITLE of "MR.GEEK".
Connect :
INTERESTING READ FOR YOU :
SHARE:
For any Queries,suggestions,feel free to Mail us at :
[email protected]
For reporting any kind of copyright voilation,mail us at : [email protected]
© copyright CODE OF GEEKS 2018