Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is union and structure in c?

1149


What is the c value paradox and how is it explained?

992


How to draw the flowchart for structure programs?

9260


Which is better pointer or array?

974


What is static memory allocation? Explain

1033


What are comments and how do you insert it in a C program?

1198


How many main () function we can have in a project?

1064


How is pointer initialized in c?

976


Difference between linking and loading?

1061


write a progrmm in c language take user interface generate table using for loop?

1996


What is function prototype?

1057


What is the difference between call by value and call by reference in c?

1115


Is it better to use malloc() or calloc()?

1065


What is string concatenation in c?

1027


Explain how do you convert strings to numbers in c?

1022