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

How would you obtain the current time and difference between two times?

1295


How can I discover how many arguments a function was actually called with?

1070


write a c program to calculate sum of digits till it reduces to a single digit using recursion

3313


What is void main ()?

1076


What are dangling pointers in c?

1236


Can you subtract pointers from each other? Why would you?

963


What is the difference between strcpy() and memcpy() function in c programming?

1090


What is %d used for?

1042


What is the value of uninitialized variable in c?

1034


How do you print an address?

1273


Which is best linux os?

1028


What are the scope of static variables?

1195


If the size of int data type is two bytes, what is the range of signed int data type?

1026


What is the use of clrscr?

1110


What is FIFO?

1728