how do u find out the number of 1's in the binary
representation of a decimal number without converting it
into binary(i mean without dividing by 2 and finding out
the remainder)? three lines of c code s there it
seems...can anyone help

Answer Posted / srsabariselvan

int main()
{
int n,i=0;
scanf("%d",&n);
while(n!=0)
{
if(n&01)
i++;
n>>=1;
}
printf("%d",i);
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does c have enums?

608


Is c still relevant?

648


Is stack a keyword in c?

640


What is pragma in c?

636


‎How to define structures? · ‎

636






How to Throw some light on the splay trees?

625


a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

663


Differentiate call by value and call by reference?

573


What does return 1 means in c?

591


Write a program to reverse a given number in c language?

626


what is bit rate & baud rate? plz give wave forms

1525


Which type of language is c?

656


c language interview questions & answer

1465


Write a program to print factorial of given number using recursion?

607


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

683