Python Program to swap two numbers using xor
Program
a = int(input("Enter the value of a:\n"))
b = int(input("Enter the value of b:\n"))
print("Values before swapping:")
print("a:\t{}\nb:\t{}".format(a,b))
a = a ^ b
b = a ^ b
a = a ^ b
print("Values after swapping:")
print("a:\t{}\nb:\t{}".format(a,b))
Output
Enter the value of a:
31
Enter the value of b:
89
Values before swapping:
a: 31
b: 89
Values after swapping:
a: 89
b: 31