Whats wrong in this methhod?


#1

Commeint setbits(unsigned int A)
{
int n,i,key,count;
key=1;
count=0;
for(i=0;i<=n;i++)
{
if(i==key)
{
count+1;
}
}

return count;

}


#2

bro you are supposed to find the number of 1 bits present in the bit representation of the given number. Your code will find number of 1s between 0 and n


#3

convert A(number) into array of 0,1 i.e. binary representation;
then your method will be perfect.
while(A!=0)
{
A=A&A-1;
count++;
}