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

Compare interpreters and compilers.

1115


What is typedf?

1164


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

1128


What is pointers in c with example?

1139


If errno contains a nonzero number, is there an error?

1432


which is an algorithm for sorting in a growing Lexicographic order

1866


regarding pointers concept

2097


What is a sequential access file?

1245


Differentiate fundamental data types and derived data types in C.

1090


What are different types of operators?

1097


Differentiate between full, complete & perfect binary trees.

1170


Explain what is the best way to comment out a section of code that contains comments?

1189


What is difference between function overloading and operator overloading?

1141


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

1302


What is .obj file in c?

1134