Exchanging the values of two variables-
Exchanging the values of two variables means swapping or interchanging their values. You can easily understood this by an example.
Suppose you have two variables a and b and you want to swap or interchange their value.
The original values of a and b are-
In python programming it is very easy to interchange the value of variables by assigning one variable value to another like this
a, b = b, a
After swapping, the result should be-
Algorithm-
- Begin
- Get the value of variables a and b
- print the value of a and b before swapping
- Assign the value of a to b and value of b to a
- print the value of a and b after swapping
- Stop
0 Comments