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

What is the purpose of main() function?

662


Explain what is the most efficient way to store flag values?

702


What is a constant?

637


What are the usage of pointer in c?

706


What are multibyte characters?

647






typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

719


Explain logical errors? Compare with syntax errors.

633


Explain the difference between null pointer and void pointer.

675


What is %s and %d in c?

594


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

651


What is the difference between procedural and functional programming?

523


What is structure in c language?

622


What is the difference between formatted&unformatted i/o functions?

620


What is non linear data structure in c?

579


Describe dynamic data structure in c programming language?

608