This is a simple program to Swap 2 Numbers, which are accepted into the variables ‘a’ and ‘b ’.

First of all, we ask the user to enter the first number and the second number.

Then we accepted integer values for the variables ‘a’ and ‘b’.

Click here to know more about ‘how to enter values’.

swap2

Now look at the code snippet:

C=b

B=a

A=c

Here we just assigned,

The value of the variable ’b’ into a new variable ‘c’.

The  value of ‘a’ to ‘b’.

Then the value of ‘c’ to ‘a’.

The we used the ‘print()’ to display the output.

swap1

Advertisements