剑指offer——面试题15.1:判断一个数是否为2的整数次方
1 #include"iostream" 2 using namespace std; 3 4 bool IsTwoPower(int n) 5 { 6 return !((n-1)&n); 7 } 8 9 int main() 10 { 11 int n; 12 while(cin>>n) 13 { 14 if(n==0) 15 { 16 cout<<"no"<<endl; 17 continue; 18 } 19 if(IsTwoPower(n)) 20 cout<<"yes"<<endl; 21 else 22 cout<<"no"<<endl; 23 } 24 return 0; 25 }