Skip to content

Commit 7a8dc7e

Browse files
committed
swapping numbers without third variable
1 parent d650b3c commit 7a8dc7e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Declare a function swap that takes num_1 and num_2 as parameters.
2+
function swap(num_1, num_2) {
3+
// At first print the numbers before swaping
4+
console.log("Before swapping:\n num_1 = " + num_1 + "\n num_2 = " + num_2);
5+
num_1 = num_1 + num_2;
6+
num_2 = num_1 - num_2;
7+
num_1 = num_1 - num_2;
8+
// Check the result by printing the output
9+
console.log("After swapping:\n num_1 = " + num_1 + "\n num_2 = " + num_2);
10+
}

0 commit comments

Comments
 (0)