All pastes #614253 Raw Edit

Perfect Numbers

public text v1 · immutable
·published 2007-07-11 13:24 UTC
rendered paste body
#include<iostream>

using namespace std;

int main()
{
 int n,m,i,sum=1;

 cout << "List all the perfect numbers less than: ";
 cin >> m;

 for(n=2;n<m;n++)
  {
   for(i=n-1;i>1;i--)
   { 
    if(n%i == 0)
     sum += i; 
   }

   if(sum == n)
    cout << n <<endl;   
 }   
 
}