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

Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

1035


Why is c faster?

1015


What is clrscr ()?

1056


what is the height of tree if leaf node is at level 3. please explain

2088


What is an array in c?

1001


Explain pointer. What are function pointers in C?

1016


What is the difference between pure virtual function and virtual function?

1067


Can we access array using pointer in c language?

1041


Is a house a mass structure?

1052


What is d scanf?

1027


In C language what is a 'dangling pointer'?

1063


What happens if you free a pointer twice?

1028


Create a simple code fragment that will swap the values of two variables num1 and num2.

1237


What is a sequential access file?

1094


What is the time and space complexities of merge sort and when is it preferred over quick sort?

1013