Give a method to count the number of ones in a 32 bit number?
Answer Posted / vignesh1988i
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned i;
int j=0,count=0;;
printf("Enter the number :");
scanf("%ld",&i);
while(j<=31)
{
if(!(((i>>j)&1)^1))
count++;
j++;
}
printf("\nnumber of 1's in ur number is : %d",count);
getch();
}
thank u
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is non linear data structure in c?
What are the different properties of variable number of arguments?
what is the structure pointer?
Which is more efficient, a switch statement or an if else chain?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
Why do we need arrays in c?
What is queue in c?
What is structure and union in c?
What is conio h in c?
What is declaration and definition in c?
Is return a keyword in c?
Write a code of a general series where the next element is the sum of last k terms.
Is c object oriented?
Why is struct padding needed?