Swap Two Values Without Using Third Variable
In this program Power Operator ( ^ ) Is Used To Swap two variables
Bitwise XOR
========================================================================
#include<iostream>
using namespace std;
main()
{
int Number1,Number2;
cout<<"Enter Number1 & Number2\n";
cin>>Number1>>Number2;
cout<<"Entered Numbers Before Swaping\n";
cout<<Number1<<" "<<Number2<<endl;
// Logic Start
Number1=Number1^Number2;
Number2=Number1^Number2;
Number1=Number1^Number2;
//Logic End
cout<<"Entered Numbers After Swaping \n";
cout<<Number1<<" "<<Number2<<endl;
}
OutPut:
=======================================================================
0 comments:
Post a Comment