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
Explain c preprocessor?
What is gets() function?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
Write a program to check prime number in c programming?
What is an expression?
How can I remove the trailing spaces from a string?
int i=10; printf("%d %d %d", i, i=20, i);
What is a program?
What is a wrapper function in c?
What are variables and it what way is it different from constants?
What do you mean by dynamic memory allocation in c? What functions are used?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
Where register variables are stored in c?
how to create duplicate link list using C???
Which is an example of a structural homology?