write a program to find out number of on bits in a number?
Answer Posted / krishna kanth
#include<stdio.h>
main()
{
int setbit=1;
int number=16;//for example
int numBitSet=0;
clrscr();
while(setbit<=number)//important and optimized condition
{
if(number&setbit)
numBitSet++;
setbit=setbit<<1;
}
printf("%d",numBitSet);
getch();
}
Is This Answer Correct ? | 10 Yes | 3 No |
Post New Answer View All Answers
application attempts to perform an operation?
What are the advantages of union?
What is the best organizational structure?
Can main () be called recursively?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
Are there constructors in c?
Does c have enums?
Array is an lvalue or not?
What is the importance of c in your views?
State the difference between x3 and x[3].
How to write a multi-statement macro?
Which header file is used for clrscr?
Is it possible to pass an entire structure to functions?
What happens if you free a pointer twice?
What is call by reference in functions?