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 / 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


Please Help Members By Posting Answers For Below Questions

What is define c?

1001


What the advantages of using Unions?

1164


Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

1018


How can I manipulate strings of multibyte characters?

1077


Why is event driven programming or procedural programming, better within specific scenario?

2365


How do you determine the length of a string value that was stored in a variable?

1081


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1651


please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................

1954


Are pointers integers in c?

1029


Is c procedural or object oriented?

953


What does *p++ do? What does it point to?

1004


How can a string be converted to a number?

965


What are the application of c?

1044


What is the use of define in c?

1001


What is && in c programming?

1112