write a program to find out number of on bits in a number?
Answer Posted / ajay vikram
void main()
{
int number,a=0,b,count=0;
printf("Enter the number : ");
scanf("%d",&number);
b = (number/2);
while(b)
{
if((number>>a)& 1)
{
count++;
}
a++;
b--;
}
printf("Number of ON Bits in the number : %d\n",count);
}
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is #include in c?
Where is volatile variable stored?
Why malloc is faster than calloc?
to find the closest pair
Explain how do you override a defined macro?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
Why c is called object oriented language?
What is the difference between pure virtual function and virtual function?
How can I make it pause before closing the program output window?
What are the types of pointers in c?
How would you obtain the current time and difference between two times?
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
I came across some code that puts a (void) cast before each call to printf. Why?
Explain what is the most efficient way to store flag values?