Ans. //( (x > 0) && ((x & (x - 1)) == 0) )
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "enter the no of : ";
cin >> x;
if( (x > 0) && ((x & (x - 1)) == 0) )
{
cout <<"no is power of 2";
}
else
{
cout <<"no is not a power of 2";
}
}
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "enter the no of : ";
cin >> x;
if( (x > 0) && ((x & (x - 1)) == 0) )
{
cout <<"no is power of 2";
}
else
{
cout <<"no is not a power of 2";
}
}
No comments:
Post a Comment