This program is to swap/exchange two numbers without using the third number in the way as given below:
Example: Suppose, there are two numbers 25 and 23.
Let
X= 25 (First number), Y= 23 (second number)
Swapping Logic:
X = X + Y = 25 +23 = 48
Y = X - Y = 48 - 23 = 25
X = X -Y = 48 - 25 = 23
and the numbers are swapped as X =23 and Y =25.
Algorithm
- STEP 1: START
- STEP 2: ENTER x, y
- STEP 3: PRINT x, y
- STEP 4: x = x + y
- STEP 5: y= x - y
- STEP 6: x =x - y
- STEP 7: PRINT x, y
- STEP 8: END
Java Program
Output:
C Program
Output:
C# Program
Output:
Python Program
Output:
PHP Program
Output: