Can you write a program to find, if the number if power of 2 or not..
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
cout<<"Enter The Number:";
cin>>num;
if(! (num &(num-1)))
cout<<"\nNumber is Power of 2";
else
cout<<"\nNumber is NOT Power of 2";
getch();
}
#include<conio.h>
void main()
{
int num;
cout<<"Enter The Number:";
cin>>num;
if(! (num &(num-1)))
cout<<"\nNumber is Power of 2";
else
cout<<"\nNumber is NOT Power of 2";
getch();
}
No comments:
Post a Comment