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
which is conditional construct a) if statement b) switch statement c) while/for d) goto
How can I list all of the predefined identifiers?
write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.
What is the difference between far and near in c?
Why doesnt the call scanf work?
What are the application of void data type in c?
What is double pointer in c?
How do I send escape sequences to control a terminal or other device?
void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply
In c programming language, how many parameters can be passed to a function ?
Define macros.
What is the best way to store flag values in a program?
Difference between pass by reference and pass by value?
using only #include
What is a pointer value and address in c?