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

Explain c preprocessor?

1060


What is gets() function?

1090


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1476


Write a program to check prime number in c programming?

1047


What is an expression?

1013


How can I remove the trailing spaces from a string?

1041


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

1565


What is a program?

1201


What is a wrapper function in c?

1084


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

1205


What do you mean by dynamic memory allocation in c? What functions are used?

1126


Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?

975


Where register variables are stored in c?

930


how to create duplicate link list using C???

2523


Which is an example of a structural homology?

1278