Program to swap two variable

Swapping means exchange. In the program exchange the value of variable.

It is done by using a temporary variable;

Program
x = input ("Enter value of x")
Y = input ("Enter value of Y")

Temp = x
x = y
y = temp

print("The value of x after:"{};format(x))
print("The value of y after:"{};format(y))

Swap variable without using temporary variable.

X = 10
y = 5

x = x+y
y = x-y
x = x-y

Print("swapping !x=",x,"y="xy)

Leave a Reply