Algorithm of exchanging the values of two variables

Algorithm of exchanging the values of two variables

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-

  1. Begin
  2. Get the value of variables a and b
  3. print the value of a and b before swapping
  4. Assign the value of a to b and value of b to a
  5. print the value of and after swapping
  6. Stop

Post a Comment

0 Comments