Playing With Bits prblm


plz check up with my code

Anshul, your code is not producing any output, and when I am submitting, it is showing TLE, so basic approach you can follow up is that, you can create a function called countsetbits, that will take two values, a and b, as you are taking as input from the user, so
int countsetbits(int a,int b)
{
int totalbits=0;
for(int i=a;i<=b;i++)
{
totalbits=totalbits+setbits(i);
}
return totalbits;
}

And then the setbit function will work as per the normal logic you use for counting the total no of set bits, i.e total no of 1’s in your value…work accordingly…