Program to swap two numbers without using the third variableThis 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
Java ProgramOutput: Enter the value of x and y 23 43 before swapping numbers: 23 43 After swapping: 43 23 C ProgramOutput: Enter the value of x and y? 13 22 before swapping numbers: 13 22 After swapping: 22 13 C# ProgramOutput: Enter the value of x and y 213 432 before swapping numbers: 213 432 After swapping: 432 213 Python ProgramOutput: Enter the value of x? 12 Enter the value of y? 24 before swapping numbers: 12 24 After swapping: 24 12 PHP ProgramOutput: Enter the value of x 55 Enter the value of y 46 before swapping numbers: 55 46 After swapping 46 55 Next Topic# |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India