write a program to find out number of on bits in a number?
Answer Posted / madhu
#include <stdio.h>
main()
{
int number;
int setbit=1; //Lets start checking from first bit
int numBitSet=0; //Number of bits set in the number
printf("enter the number");
scanf("%d", &number);
while(setbit>0)
{
if(number&setbit) //bit wise and
numBitSet++;
setbit=setbit<<1;
}
printf("%d",numBitSet);
}
full program of the first ans...
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is union and structure in c?
What is the c value paradox and how is it explained?
How to draw the flowchart for structure programs?
Which is better pointer or array?
What is static memory allocation? Explain
What are comments and how do you insert it in a C program?
How many main () function we can have in a project?
How is pointer initialized in c?
Difference between linking and loading?
write a progrmm in c language take user interface generate table using for loop?
What is function prototype?
What is the difference between call by value and call by reference in c?
Is it better to use malloc() or calloc()?
What is string concatenation in c?
Explain how do you convert strings to numbers in c?