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
Are the variables argc and argv are local to main?
What is the general form of a C program?
When was c language developed?
How do you view the path?
Is stack a keyword in c?
Can you add pointers together? Why would you?
Explain what is the most efficient way to store flag values?
Can you please explain the difference between strcpy() and memcpy() function?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
What are operators in c?
What is the difference between ++a and a++?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
What is logical error?
What is the default value of local and global variables in c?
Describe explain how arrays can be passed to a user defined function