How Do You Swap Two Numbers Without Using The Third Variable?
We can do it by single statement
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...
Swapping two numbers(integers) without using third variable:
All the above may cause overflow.
The one line answer which is full proff is this:
suppose we have a=3 n b=2
a= a+b (a=5)
We can do it by using X-OR
(operate it from right)
Didn't find the answer you were looking for?
Ask a Question