write a program to find out number of on bits in a number?

Answer Posted / vaishu and hema

main()
{
int n,count=0,rem;
scanf("%d",&n);
while(n>0)
{
rem=n%2;
if(rem==1)
count++;
n=n/2;
}
printf("The number of on bits in the number is %d",count);
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I do graphics in c?

597


Can two or more operators such as and be combined in a single line of program code?

811


Why do we use int main?

610


Do you know the use of 'auto' keyword?

662


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

671






What is c++ used for today?

669


How old is c programming language?

581


Should a function contain a return statement if it does not return a value?

600


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2335


What is the return type of sizeof?

596


What is pointer to pointer in c?

635


Which header file is used for clrscr?

583


What is the size of enum in c?

624


how logic is used

1503


Why main is not a keyword in c?

652