This is the code I have written for the program “Power of 2”. I have successfully submitted the code on Leetcode but in here it is giving me wrong answer. can anyone help me in this? Thank you in advance.
int main()
{
int n;
cin>>n;
if(n < 0){
cout<<false;
}
int ctr = 0;
while(n > 0){
if(n & 1 == 1){
ctr++;
}
n >>= 1;
}
if(ctr == 1){
cout<<true;
}
else{
cout<<false;
}
return 0;
}