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
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
Why is c faster?
What is clrscr ()?
what is the height of tree if leaf node is at level 3. please explain
What is an array in c?
Explain pointer. What are function pointers in C?
What is the difference between pure virtual function and virtual function?
Can we access array using pointer in c language?
Is a house a mass structure?
What is d scanf?
In C language what is a 'dangling pointer'?
What happens if you free a pointer twice?
Create a simple code fragment that will swap the values of two variables num1 and num2.
What is a sequential access file?
What is the time and space complexities of merge sort and when is it preferred over quick sort?