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
What are the disadvantages of external storage class?
Why is c fast?
When can you use a pointer with a function?
Why structure is used in c?
What are the 5 organizational structures?
Explain what is the use of a semicolon (;) at the end of every program statement?
What is a program flowchart?
What does void main return?
how to build a exercise findig min number of e heap with list imlemented?
What is the correct code to have following output in c using nested for loop?
Can we compile a program without main() function?
What is difference between structure and union in c?
What is the correct declaration of main?
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What is the difference between exit() and _exit() function?