Thursday, 29 January 2015

c++ program to find the perfect number.

 
#include<iostream>
int main()
{
  for (int target=1; target < 1000; target++)
  {
  int sum=0;
  for(int i=1;i<target && sum < target+1; i++)
  {
    if(target%i == 0)
    { 
      sum += i;
    } 
  }
    if(sum == target)
    { 
      std::cout<<"\nperfect number"<<target;
    } 
  }