Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions swap,cpp.cpp

This file was deleted.

38 changes: 38 additions & 0 deletions swapping_without_using_third_variable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<iostream>
using namespace std;
void method1(int a,int b){
a=a+b;
b=a-b;
a=a-b;
cout<<"value of a and b after swapping is: "<<a<<" "<<b<<endl;

}
void method2(int a,int b){
//this method will not work if either a or b=0;
a=a*b;
b=a/b;
a=a/b;
cout<<"value of a and b after swapping is: "<<a<<" "<<b<<endl;

}
void method3(int a,int b){
//this method will mot work if both the variables are 0.
a=a^b;
b=a^b;
a=a^b;
cout<<"value of a and b after swapping is: "<<a<<" "<<b<<endl;
}

int main()
{
int a,b;
cin>>a>>b;
//Using Arithmetic Operators
method1(a,b);
method2(a,b);
//Using Bitwise XOR
method3(a,b);
return 0;


}