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 the use of extern in c?

1064


What does the error 'Null Pointer Assignment' mean and what causes this error?

1185


Can an array be an Ivalue?

1066


If null and 0 are equivalent as null pointer constants, which should I use?

1145


Can a variable be both const and volatile?

1093


code for replace tabs with equivalent number of blanks

2108


What are variables and it what way is it different from constants?

1205


Can we access the array using a pointer in c language?

1012


There seem to be a few missing operators ..

1016


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

2123


Define Spanning-Tree Protocol (STP)

1078


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

1092


Explain what is wrong in this statement?

1083


Explain built-in function?

1101


What is a null pointer in c?

1149