01 C | Swap two numbers without using third variable

Опубликовано: 20 Ноябрь 2013
на канале: Yusuf Shakeel
15,483
56

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  


Смотрите видео 01 C | Swap two numbers without using third variable онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Yusuf Shakeel 20 Ноябрь 2013. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 15,483 раз и оно понравилось 56 посетителям.