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 would you obtain the current time and difference between two times?
How can I discover how many arguments a function was actually called with?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
What is void main ()?
What are dangling pointers in c?
Can you subtract pointers from each other? Why would you?
What is the difference between strcpy() and memcpy() function in c programming?
What is %d used for?
What is the value of uninitialized variable in c?
How do you print an address?
Which is best linux os?
What are the scope of static variables?
If the size of int data type is two bytes, what is the range of signed int data type?
What is the use of clrscr?
What is FIFO?