Skip to content

Commit d819d8d

Browse files
authored
Create Swapping 2 variables without 3rd variable
1 parent c540474 commit d819d8d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int x = 10, y = 5; //Sample Values
7+
8+
// Code to swap 'x' and 'y'
9+
x = x + y; // x now becomes 15
10+
y = x - y; // y becomes 10
11+
x = x - y; // x becomes 5
12+
cout << "After Swapping: x =" << x << ", y=" << y;
13+
}

0 commit comments

Comments
 (0)