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


Please Help Members By Posting Answers For Below Questions

What is #include in c?

787


Where is volatile variable stored?

836


Why malloc is faster than calloc?

798


to find the closest pair

2057


Explain how do you override a defined macro?

799


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

999


Why c is called object oriented language?

802


What is the difference between pure virtual function and virtual function?

866


How can I make it pause before closing the program output window?

780


What are the types of pointers in c?

736


How would you obtain the current time and difference between two times?

977


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

916


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'); }

931


I came across some code that puts a (void) cast before each call to printf. Why?

959


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

925