-
Notifications
You must be signed in to change notification settings - Fork 2
/
08.cpp
40 lines (40 loc) · 806 Bytes
/
08.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream>
using namespace std;
//swapping using a temporary variable
void SwapT(int *n1,int *n2)
{
int temp;
temp=*n1;
*n1=*n2;
*n2=temp;
}
//using + and - operator
void SwapO(int *n1,int *n2)
{
*n1 = *n1 + *n2;
*n2 = *n1 - *n2;
*n1 = *n1 - *n2;
}
//using bitwise operator
void SwapB(int *n1,int *n2)
{
*n1 = *n1 ^ *n2;
*n2 = *n1 ^ *n2;
*n1 = *n1 ^ *n2;
}
int main()
{
//to swap the two numbers
int n1,n2;
cout<<"Enter number 1 : ";
cin>>n1;
cout<<"enter number 2 : ";
cin>>n2;
cout<<"Before Swapping : "<<endl;
cout<<"N1 : "<<n1<<endl;
cout<<"N2 : "<<n2<<endl;
SwapB(&n1,&n2);
cout<<"After Swapping :"<<endl;
cout<<"N1 : "<<n1<<endl;
cout<<"N2 : "<<n2<<endl;
}