c++ program to check whether a given number is a perfect number or not

#include <iostream>
using namespace std;
void main()
{
int n,i,sum;
  int mn,mx;

  cout<<"Input the  number : ";
  cin>>n;
    sum = 0;
 cout<<"The positive divisor  : ";
    for (i=1;i<n;i++)
      {
      if(n%i==0)
         {
         sum=sum+i;
         cout<<"   "<<i;
         }
       }
   cout<<"\nThe sum of the divisor is : "<<sum;
    if(sum==n)
      cout<<"\nSo, the number is perfect.";
    else
      cout<<"\nSo, the number is not perfect.";
    cout<<endl;
system ("pause");
}


Test Data : 
Input the number : 56 
Expected Output :
The positive divisor : 1 2 4 7 8 14 28 
The sum of the divisor is : 64 
So, the number is not perfect.

c++ program to check whether a given number is a perfect number or not c++ program to check whether a given number is a perfect number or not Reviewed by Unknown on May 21, 2017 Rating: 5

No comments:

Powered by Blogger.