adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to check a given number is perfect or not Using Calss

Program in C++ to check a given number is perfect or not Using Calss


PROGRAM CODE
#include<iostream>
#include<conio.h>
 using namespace std;
  class Perfect
  {
   private:
    int n;
   public:
    Perfect(){}
    Perfect(int n1){ n=n1; }
    ~Perfect(){}
    void input()
       {
           cout<<"Input a number:-";
           cin>>n;
       }
      int isPerfect()
       {
        int sum=0,i;
        for(i=1;i<n;i++)
         {
          if(n%i==0)
            {
             sum+=i;
      }
      }
   if(sum==n)
     return 1;
   else
     return 0;
    }
  };
  int main()
     {
       Perfect p1;
       p1.input();
       int n=p1.isPerfect();
       if(n==1)
         cout<<"Perfect no.";
       else
         cout<<"Not Perfect no.";
      return 0;
     }
Output:-





Post a Comment

0 Comments