GeeksforGeeks » Interview Questions
Amazon Interview Question for Software Engineer/Developer about CPuzzles
(3 posts)-
Find out what this function does.
int foo(int n) { int t,count=0; t=n; while(n) { count=count+1; n=(n-1)&t; } return count; } -
Let the number we get after flipping all the bits of n after the leftmost set bit is n'.
The function foo() returns n - n'
For example if n is 9 (000..1001) then n' would be 6(000..0110). So for 9 fun returns 3 (9 -6)
For example if n is 7 (000..0111) then n' would be 0(000..0000). So for 7 fun returns 7 (9 -0)
-
explain for 20 and 21. i m getting 3 and 7. how??
Reply
You must log in to post.