Exchanging values of two variables

Exchanging values of two variables


Problem definition: Exchanging values of two variables.

Analysis: Two variables x and y contains two different values.

Swap the values of x and y such that x has y′s value and y has x′s value.

Solving by example: Let us consider two variables x and y,containing values 8 and 20 respectively.

The original values of x and y are:

The requirement is once the algorithm is performed, the results should be

If you think by just saying,

x=y; y=x;

The value gets swapped, then you are mistaken.

These instruction are atomic in nature and hence x = y means that the value of ‘x’ is lost.

So,we have to use a temporary variable,temp to store the value of ‘x’.

The value of ‘x’ and ‘y’ is swapped.


Algorithm Definition



Python : Exchanging values of two variables Program List




Program [1]

Program to convert the distance (in feet) to inches, yards,  and miles


View Solution


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad