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

Answer Posted / minisha

int count(unsigned int n)
{
int c=0;
while(n)
{
n=n&(n-1);
c++
}
return c;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should structures be passed by values or by references?

812


Can a void pointer point to a function?

758


What is the explanation for modular programming?

898


What's the right way to use errno?

841


What does main () mean in c?

850


How can I send mail from within a c program?

776


What is a static variable in c?

861


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

844


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

812


Explain indirection?

864


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1628


What is use of #include in c?

817


What is difference between arrays and pointers?

762


How do I convert a string to all upper or lower case?

861


How do you write a program which produces its own source code as output?

832