mangal.govind
BAN USER 0of 0 votes
Answershow do you count set bits in a Float number?
 mangal.govind in India Report Duplicate  Flag  PURGE
Adobe Software Engineer / Developer Knowledge Based  0of 0 votes
Answersyou have only two functions
 mangal.govind in India
1.Loop(count) : Loops for count times
2.Increment(Count): increases a number count times
How would you achieve AB using only these two operations?
Remember you have no operation like comparison,bitwise operations or anything, just these two you have...... Report Duplicate  Flag  PURGE
Adobe Software Engineer / Developer Knowledge Based
if start=2 and end =6 ,index starting from 1 then result should be 111110
{
int num=0,start=2,end=6,i,result=0;
for(i=start1;i<end;i++) // if you start index from 0 then i=start
num+=pow(2,i);
result=resultnum;
printf("%d",result);
return 0;
}

mangal.govind
April 13, 2012 we don't have ++ and  operators so we can't use those, in my solution above if you see i have given the logic first, using loop(n) and increment(n) but to check if logic works we had to use inbuilt for loop to implement loop and increment .... otherwise had to implement loop and increment separately... din't use it for logic implementation.... and it works for all if a > or < or = b
But what you are doing here is just making use of ++ and  operator to implement the ab ,c heck pls....
in this solution here i have taken integer as 32 bit long and while looping in for loop i can compare j to (INT_MAX/2)1 times otherwise it will go in infinite loop.... so one additional L++ required after the loop..... and one additional loop for other half rotation.....
 mangal.govind April 12, 2012My Bad.
increament(a) means increase 'a' by 1 not increase 'b' by a times if b.increament(a)
@roshan:negation of a number was not allowed.
@mridul: when you do increament(1) it will result in 0 not in 2,just think......
Forgot to mention A and B are integers..... so function will be something like
int result(int a,int b) so for a=5,b=3 it returns 2.
easy to understand and and correct way.... complexity O(m)... thanks sonia!!!
 mangal.govind June 17, 2011Open Chat in New Window
if start=2 and end =6 ,index starting from 1 then result should be 111110
 mangal.govind April 13, 2012