Write a python program to swap two numbers without using third variable.

 Program:-
a=int(input(“a=”))
b=int(input(“b=”))
print(“Values before swappingn”,“a=”,a,“b=”,b)
a=a+b
b=a-b
a=a-b
print(“Values after swappingn”,“a=”,a,“b=”,b)

Output:-

a=2
b=3
Values before swapping
a= 2 b= 3
Values after swapping
a= 3 b= 2


Leave a Reply

Your email address will not be published.