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

Answer Posted / venkat reddy

main()
{
int n,counter;
printf("enter a number");
scanf("%d",&n);// let n=5
while(n>0)
{
counter++;
n=n&(n-1);
}
printf("%d",counter);
getch();
}

Is This Answer Correct ?    11 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a nested formula?

793


Are there any problems with performing mathematical operations on different variable types?

801


Explain 'bit masking'?

838


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

891


Explain the difference between malloc() and calloc() in c?

807


What is optimization in c?

742


What does s c mean on snapchat?

783


Explain what is the difference between a string and an array?

892


How do you construct an increment statement or decrement statement in C?

992


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

887


What is the purpose of void pointer?

791


What is the difference between fread buffer() and fwrite buffer()?

902


How can you increase the size of a statically allocated array?

843


Tell us bitwise shift operators?

804


What is function in c with example?

835