Skip to content

Commit 5378116

Browse files
authored
Swap 2 numbers
1 parent 8eda062 commit 5378116

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

swap_2_numbers.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
int main(){
3+
int a=10 , b=11 , x=20 , y=22 , t=0;
4+
5+
6+
//Without 3rd variable
7+
a=a+b;
8+
b=a-b;
9+
a=a-b;
10+
11+
std::cout<<"\nswaping without 3rd :: "<<a<<" , "<<b;
12+
13+
//with 3rd variable
14+
t=x;
15+
x=y;
16+
y=t;
17+
18+
std::cout<<"\nswaping with 3rd :: "<<x<<" , "<<y;
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)