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
Is null a keyword in c?
How to write c functions that modify head pointer of a linked list?
How can I call a function with an argument list built up at run time?
How many levels of pointers have?
What are the uses of null pointers?
write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34
Explain 'bus error'?
can we have joblib in a proc ?
I heard that you have to include stdio.h before calling printf. Why?
What are types of functions?
What are the different types of C instructions?
What is a pointer in c?
What is c standard library?
Why c is called a middle level language?
Explain what are header files and explain what are its uses in c programming?