Hey Priyanka..

Both code are same here u induse temp variable and using later to assign it
with a,


so shrinivas code is right and its working fine... in code value of a is
being used in smart way..

a= a^b

if we again do ex-oring a with b den we will get a orignal value.

a = a^b
 suppose value of a= 3 and b = 1 then a =2(a = a^b ) but after we again do
ex-oring then a = 3(a = a^b )

a = 3 = 011
b= 1 = 001  after exroing
-------------------
a = 2 =010 (a = a^b)
b=1 = 001
-----------------
a = 3 = 011 (that value being used in that expression of shrinivas code
b=(a^b)&b; in place of bracket.

-- 
Thanks & Regards

Umesh kewat


On Thu, Jul 1, 2010 at 8:55 AM, Priyanka Chatterjee <dona.1...@gmail.com>wrote:

> @shrinivas : your iterative code is wrong
>
> It should be:
>
>>
>> int add(int a, int b)
>> { int temp;
>>           do
>>           {
>>                      temp=a^b;
>>                      b=a&b;
>>                      b=b<<1;
>>
>                          a=temp;
>
>>           } while(b);
>>
>>           return(a);
>> }
>>
>>
>> it is working well for negative numbers also . i tried lot but can not
>> understand logic behind it can any one explain it in easy manner ...
>> thanks in advance
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Thanks & Regards,
> Priyanka Chatterjee
> Final Year Undergraduate Student,
> Computer Science & Engineering,
> National Institute Of Technology,Durgapur
> India
> http://priyanka-nit.blogspot.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to