Anonymous

How Do You Swap Two Numbers Without Using The Third Variable?

6 Answers

Nagarjuna Reddy Profile
Nagarjuna Reddy answered
We can do it by single statement

a=(a+b)-(b=a);
Anonymous Profile
Anonymous answered
The best way to swap between two numbers is by using the basic concepts of mathematics,nothing more...it's so easy!!  Consider a=10,b=5.  Now take ,  a=a+b  (i.e.10+5=15)  b=a-b; (i.e.15-5=10)  a=a-b  (i.e. 15-10=5)    That's so simple...
Anonymous Profile
Anonymous answered
Swapping two numbers(integers) without using third variable:
A=a^b;
b=a^b;
a=a^b;
Anonymous Profile
Anonymous answered
All the above may cause overflow.
The one line answer which is full proff is this:
A=a+b-(b=a)

Answer Question

Anonymous