//Program to find power of 2
#include <iostream>
using namespace std;
class power
{
int no,remainder,flag=0;
public:
void input(void);
void output(void);
};
void power :: input(void)
{
cout<<"\nEnter a Number: ";
cin>>no;
}
void power::output(void)
{
while(no>2)
{
remainder=no%2;
if(remainder==1)
{
flag=1;
break;
}
else
no=no/2;
}
if(flag==1)
cout<<"\nThe entered number is not Power of 2"<<endl;
else
cout<<"\nThe entered number is Power of 2"<<endl;
}
int main()
{
int no, remainder, flag=0;
power two;
two.input();
two.output();
return 0;
}
OUTPUT:
#include <iostream>
using namespace std;
class power
{
int no,remainder,flag=0;
public:
void input(void);
void output(void);
};
void power :: input(void)
{
cout<<"\nEnter a Number: ";
cin>>no;
}
void power::output(void)
{
while(no>2)
{
remainder=no%2;
if(remainder==1)
{
flag=1;
break;
}
else
no=no/2;
}
if(flag==1)
cout<<"\nThe entered number is not Power of 2"<<endl;
else
cout<<"\nThe entered number is Power of 2"<<endl;
}
int main()
{
int no, remainder, flag=0;
power two;
two.input();
two.output();
return 0;
}
OUTPUT:
No comments:
Post a Comment