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 is realloc in c?
int i=10; printf("%d %d %d", i, i=20, i);
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
How can I generate floating-point random numbers?
about c language
What is a structure and why it is used?
What is use of null pointer in c?
What is a static variable in c?
Do string constants represent numerical values?
What happens if you free a pointer twice?
please send me the code for multiplying sparse matrix using c
code for find determinent of amatrix
What is the explanation for the dangling pointer in c?
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
In C language, a variable name cannot contain?