top of page

Write a program to find whether a number is power of 2?

  • Writer: prashant raj
    prashant raj
  • Mar 18, 2022
  • 1 min read


#include <iostream>

using namespace std;

int main()
{
    int a = 128;
    int b = a-1;
    if(a && !(a & b))
    {
        cout<<"Number is power of 2"<<endl;
    }
    else {
        cout<<"Number is not power of 2"<<endl;
    }
    
}


 
 
 

Comentários


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page