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
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
How a string is stored in c?
What is a function simple definition?
If I have a char * variable pointing to the name of a function ..
Write a program to reverse a given number in c?
Write a program to print ASCII code for a given digit.
Combinations of fibanocci prime series
Explain what does it mean when a pointer is used in an if statement?
What is switch in c?
Why can arithmetic operations not be performed on void pointers?
Why c is called free form language?
How do I send escape sequences to control a terminal or other device?
Can the sizeof operator be used to tell the size of an array passed to a function?
What is an expression?
Explain how can I right-justify a string?