Swapping of two variable without using third variable by R4R Team

What is swapping ?

Exchange the value of the two variable which is already exist is called swapping.

Example -

Before swapping
a=10
b=20
After swapping
a=20
b=10

program -

print("Enter first number")
a=int(input())
print("Enter second number")
b=int(input())
print("Before swapping -")
print(a,b)
a=a+b
b=a-b
a=a-b
print("After swapping -")
print(a,b)


output -

Enter first value
12
Enter second value
13
Before swapping -
12 13
After swapping -
13 12


- In this program, we swap two number without using the third variable,here the main code is a=a+b, b=a-b, a=a-b which are responsible to swap two values.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!