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;
}
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.......