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
How a string is stored in c?
Is python a c language?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
What is a far pointer in c?
How does normalization of huge pointer works?
What is getch c?
What are the different types of objects used in c?
How do you initialize pointer variables?
What is local and global variable in c?
Which is the best website to learn c programming?
What is the difference between char array and char pointer?
Is int a keyword in c?
How can you increase the size of a dynamically allocated array?
Why isn't any of this standardized in c? Any real program has to do some of these things.
Why c is called procedure oriented language?