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 are structure passing and returning implemented?
What is the use of static variable in c?
what is ur strangth & weekness
Difference between linking and loading?
What is the scope of global variable in c?
how can I convert a string to a number?
How many levels of indirection in pointers can you have in a single declaration?
How do I swap bytes?
What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?
What is the right way to use errno?
What is New modifiers?
What does c mean before a date?
Explain what are the different file extensions involved when programming in c?
Explain how can I right-justify a string?
What is the full form of getch?