program for perfect number

Hi,
I am trying to get the output of the program as the perfect number along with its divisors. I am able to print out the perfect number but not its divisors alongside it. Below is the code.

How do I get the output as ( 6 = 1 + 2 +3 ) and so on for other perfect numbers.

#include<iostream>
#include<string>

using namespace std;

const int LIMIT = 9999;

int sum_of_proper_divisors(int n)
{
int sum_of_divisors = 0;
int proper_divisor = 1;
while (proper_divisor < n)
{
if((n % proper_divisor)== 0)
sum_of_divisors = sum_of_divisors + proper_divisor;
proper_divisor++;
}
// cout<<"N value: "<<n<<" Sum of divisors"<<sum_of_divisors<<endl;
return sum_of_divisors;
}
bool is_perfect(int n)
{
if (sum_of_proper_divisors(n)!= n)
return false;
else
return true;
}

int main()
{
for (int n = 1; n <= LIMIT; n++)
{
if (is_perfect(n))
cout << n << " = " <<endl;
}
return 0;
}
Topic archived. No new replies allowed.