Sep 4, 2009

Swapping two variables

we can have a lot of fun with any programing languages, if you are understanding the concept and logic clearly, generally to swap two variables, we need a temp variable, but it can be done without that third variable too...
if we consider two variables x and y....
Here is the logic to swap two variables

x=x-y;
y=x+y;
x=y-x;

Have a check it out...

No comments:

Post a Comment

Post a Comment

Note: Only a member of this blog may post a comment.