Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Monday

C++ TUTORIAL 16: CLASS

//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:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...