Program for swapping between two numbers without using third variable

Q. A = 20 and B = 40 perform swapping between A and B without using thrid variable.

Logic :-

A = A + B;

B = A – B;

A = A – B;

Answer :-

Now, we put values of a and b in above logic.

A = 20 + 40 = 60

B = 60 – 40 = 20

A = 60 – 20 = 40

after performing above operation values will be,

A = 40

B = 20

PROGRAM :-

OUTPUT :-