Click To Get Off-Campus Placement Jobs Info !!!
Capgemini Recruitment Process 2020 – Updated Test Pattern and Selection Process in Details Latest Pattern !!
Program Discussion :: Basics
Home > Programs > Basics

75 / 244

Write a program to find the number is power of 2 or not.

Answer:

#include<stdio.h>
#include<iostream>
using namespace std;
#define bool int
/* Function to check if x is power of 2*/
bool isPowerOfTwo (int x)
{
/* First x in the below expression is for the case when x is 0 */
return x && (!(x&(x-1)));
}
/*Driver program to test above function*/
int main()
{
isPowerOfTwo(31)?cout<<"Yes\n": cout<<"No\n";
isPowerOfTwo(16)? cout<<"Yes\n": cout<<"No\n";
return 0;
}

Asked In :: PEOL Global Edge

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: