Answer to Question define-8

  // IsPerfect(n) returns true if n is a perfect number,
  // false if not.
  //
  // A perfect number is a positive integer that is equal
  // to the sum of its proper divisors.
  //
  // Requirement: n > 0.

  bool isPerfect(int n)
  {
    int sum = 0;
    for(int i = 1; i < n; i++)
    {
      if(n % i == 0)
      {
        sum += i;
      }
    }
    return (sum == n);
  }