Quote of the day

Wednesday, January 05, 2011

swapping numbers without temp variable in c#

We all know, swapping numbers with temp variable is possible and easy. Recently I just rememberd of one of the interview questions "swap 2 numbers without using temp variable". I started thinking and did that in c#.

Following is the code which swaps 2 numbers without using temp variable


Output:

I was struggling by trying with different formulae, but nothing worked. I didn't think that we can recalculate first variable for resulting the output.
I got the idea from this post answered by this member.

No comments: