Count set bit program

#include
using namespace std;
int main() {
int n,a;
int ans=0;
cin>>n;
while(n>0)
{
cin>>a;
while(a>0)
{ a=(a>>1);
ans=ans+(a&1);
}
cout<<ans<<endl;
n–;
}
return 0;
}

Plz send your code by saving on ide only

#include
using namespace std;
int main() {
int n,a;
int ans=0;
cin>>n;
while(n>0)
{
cin>>a;
while(a>0)
{ a=(a>>1);
ans=ans+(a&1);
}
cout<<ans<<endl;
n–;
}
return 0;
}

I have modified your code a little bit, since your code was not giving any answer.