In this video we will learn to swap two numbers stored in two variables without taking help of a third variable.
In this video we are dealing we are dealing with a general formula which works perfectly well for both positive and negative values.
-----------------------------------------
Case 1: For two positive values
(Kindly watch the video)
-----------------------------------------
Case 2: For one positive and one negative value
If x = 10 and y = -20
x = x + y = 10 + (-20) = -10
y = x - y = (-10) - (-20) = 10
x = x - y = (-10) - 10 = -20
Now, x = -20 and y = 10
Value swapped.
---------------------------------------
Case 3: For two negative values
If x = -10 and y = -20
x = x + y = (-10) + (-20) = -30
y = x - y = (-30) - (-20) = -10
x = x - y = (-30) - (-10) = -20
Now, x = -20 and y = -10
Value swapped.
---------------------------------------
Thanks for reading and thanks for watching :-)
Complete Playlist:
• Programming
Also watch:
Swap two numbers using XOR
• 13 C | Swap two numbers using XOR
Watch video 01 C | Swap two numbers without using third variable online, duration hours minute second in high quality that is uploaded to the channel Yusuf Shakeel 20 November 2013. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 15,483 times and liked it 56 visitors.