Thursday, August 5, 2010

How to swap two variables, without using third variable ?

 How to swap two variables, without using third variable ? Hi this question was asked in my interview.  Ans is :  a=a+b; b=a-b; a=a-b;  Any other solution? a=a*b/(b=a); b=(a+b)-(a=b); use xor to swap  a = a^b b= a^b a= a^b Ans is :  a=a*b; b=a/b; a=a/b;





Join NOW !!!




--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

No comments:

Post a Comment