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 the use of extern in c?
What does the error 'Null Pointer Assignment' mean and what causes this error?
Can an array be an Ivalue?
If null and 0 are equivalent as null pointer constants, which should I use?
Can a variable be both const and volatile?
code for replace tabs with equivalent number of blanks
What are variables and it what way is it different from constants?
Can we access the array using a pointer in c language?
There seem to be a few missing operators ..
Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop
Define Spanning-Tree Protocol (STP)
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
Explain what is wrong in this statement?
Explain built-in function?
What is a null pointer in c?