Playing with Bits

#include<bits/stdc++.h>
using namespace std;

int countSetBits(int n)
{
// base case
if (n == 0)
return 0;
else
return 1 + countSetBits(n & (n - 1));
}
int main() {
int t;
cin >> t;
while(t–)
{
int a,b,i,c=0;
cin >> a,b;
for(i=a;i<=b;i++)
{
c+=countSetBits(i);
}
cout<<c<<endl;
}
return 0;
}

what is wrong with the code?

Hey @namanitsofficial
Please share your code in some online ide

error
this should be
cin>>a >>b;

And I am asking for ur code in IDE that means ,it should have proper indentation.,u directly copy pasted from here

And I am asking for ur code in IDE that means ,it should have proper indentation.,u directly copy pasted from here

  • Ok Sir I will take care of it the next time :joy:
1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.