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 are the disadvantages of external storage class?

1042


Why is c fast?

1043


When can you use a pointer with a function?

1050


Why structure is used in c?

1174


What are the 5 organizational structures?

1014


Explain what is the use of a semicolon (;) at the end of every program statement?

1214


What is a program flowchart?

1174


What does void main return?

1104


how to build a exercise findig min number of e heap with list imlemented?

2066


What is the correct code to have following output in c using nested for loop?

1067


Can we compile a program without main() function?

1109


What is difference between structure and union in c?

976


What is the correct declaration of main?

1198


Which header file should you include if you are to develop a function which can accept variable number of arguments?

1374


What is the difference between exit() and _exit() function?

1024