C++ Program to find Perfect Numbers

ad+1

Before looking at the coding of program. Lets discuses Perfect Numbers. Perfect numbers are those number which are equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (That sum is also known as its aliquot sum).


Program:

// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com

#include<iostream>
using namespace std;

int main()
{
  int n=0, sum=0;
 
  cout<<"Enter Number: ";
  cin>>n;
 
  for(int i=1; i<n; i++)
  {
      if(n%i==0)
      {
      sum=sum+i;
      }
  }
 
    if(sum==n)
  cout<<"Entered Number is a Perfect Number" <<endl;
 
  else
  cout<<"Enter Number is Not a Perfect Number" <<endl;
}

Output:

0 comments: