Wednesday, September 24, 2008

program to check how many 1 there on binary code of a number

prg to chk how many 1 there on binary code of a number.......(popular q in interviews)




Program
#include

int main()
{
int i=10;
int count=0;


while(i)
{
if(i &1==1)
{
count++;
}
i>>=1;
}
printf("%d",count);
return 0;
}

No comments:

Post a Comment

Thanks to given comments.......

My Blog List