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

Give a method to count the number of ones in a 32 bit number?

Answer Posted / jayaprakash

#include<stdio.h>
#include<conio.h>

main()
{
int i;
int n;
int count=0;
int j;
int res=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(j=15;j>=0;j--)
{ i=1;
i=i<<j;
res=i&n;
if(res!=0)
count++;
}
printf("\nNumber of ones is:%d",count);


getch();

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is realloc in c?

1018


int i=10; printf("%d %d %d", i, i=20, i);

1549


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

1162


How can I generate floating-point random numbers?

1041


about c language

1961


What is a structure and why it is used?

1135


What is use of null pointer in c?

959


What is a static variable in c?

1067


Do string constants represent numerical values?

1323


What happens if you free a pointer twice?

1027


please send me the code for multiplying sparse matrix using c

2120


code for find determinent of amatrix

1917


What is the explanation for the dangling pointer in c?

1062


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

1053


In C language, a variable name cannot contain?

1222