This is the blog of my interest.(Chess,funny Tech,puzzle etc)
Let us assume two numbers and b with some initial values say a=5,b=6Now perform the given below logic on original values of a and b step 1: a=a-b;step 2: b=a+b;step 3: a=b-a;after processing the logic, values of and b are swapped without use of any temporary variable.Now a=6 and b=5
same solution u can write in below formateb=a-b+(a=b)
Yes kuldeep is correct , butadding/subtracting may cause overflow
SathishUr sol'n is very compact...Gud job
Hi frendz, here is an another solutio for the problem :)step 1: a=a*b;step 2: b=a/b;step 3: a=a/b;
One more solution for the problemstep 1: a=a^b;step 2: b=a^b;step 3: a=a^b;
Post a Comment
6 comments:
Let us assume two numbers and b with some initial values say a=5,b=6
Now perform the given below logic on original values of a and b
step 1: a=a-b;
step 2: b=a+b;
step 3: a=b-a;
after processing the logic, values of and b are swapped without use of any temporary variable.
Now a=6 and b=5
same solution u can write in below formate
b=a-b+(a=b)
Yes kuldeep is correct , but
adding/subtracting may cause overflow
Sathish
Ur sol'n is very compact...Gud job
Hi frendz, here is an another solutio for the problem :)
step 1: a=a*b;
step 2: b=a/b;
step 3: a=a/b;
One more solution for the problem
step 1: a=a^b;
step 2: b=a^b;
step 3: a=a^b;
Post a Comment