All pastes #614255 Raw Edit

Perfect Numbers

public text v1 · immutable
·published 2007-07-11 13:26 UTC
rendered paste body
//This program lists all the perfect numbers less than a given positive integer(user input)

#include<iostream>

using namespace std;

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;   
 }   
 
}