write a program to find out number of on bits in a number?

Answer Posted / ram

#include<stdio.h>
void main()
{
int a,count=0;
printf("enter a");
scanf("%d",&a);
while(a>0)
{
if(a%2==1)
count++;
a=a>>1;
}
printf("no of on bits =%d ",count);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical

2063


The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

993


Explain how are portions of a program disabled in demo versions?

842


how logic is used

1680


What is non linear data structure in c?

748






What is the difference between array and pointer in c?

783


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

1685


Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1

3918


Explain what is the difference between a free-standing and a hosted environment?

868


Is main is user defined function?

831


Is c easy to learn?

722


What is difference between static and global variable in c?

734


What are nested functions in c?

747


Array is an lvalue or not?

828


What is header file definition?

798