#5 Leetcode (Power of 2)

Bhuwan SharmaBhuwan Sharma
1 min read
#include <iostream>
#include <math.h>
using namespace std;

int main(){
int power, i=0, n;
    int ans = 0;
    cout<<"enter: ";
    cin>>n;

while(i<=30){
    power = pow(2,i);
    if(power == n){
        cout<<true;
        break;}
         i++;
    }if(power!=n & n!=0){
        cout<<false;
    }else if(n==0){
        cout<<"Can't be determined";
    }
}
0
Subscribe to my newsletter

Read articles from Bhuwan Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Bhuwan Sharma
Bhuwan Sharma