write a program to find out number of on bits in a number?
Answer Posted / rajkumar
#include<stdio.h>
void main()
{
int a,count=0;
while(a>0)
{
if(a%2==1)
count++;
a=a>>1;
}
printf("no of on bits =%d ",count);
}
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
Explain why can’t constant values be used to define an array’s initial size?
What is the difference between exit() and _exit() function?
When is a void pointer used?
What does the characters “r” and “w” mean when writing programs that will make use of files?
What is the maximum no. of arguments that can be given in a command line in C.?
Whats s or c mean?
Can include files be nested? How many levels deep can include files be nested?
Can variables be declared anywhere in c?
main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above
What is a substring in c?
Why do we use int main instead of void main in c?
What is the difference between fread and fwrite function?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
What is action and transformation in spark?
How to Throw some light on the splay trees?