I have to write a C++ program that finds all the perfect numbers between 1 to 10,000 and print out the factors after the code finds them. I have written the code to find the numbers, but cant seem to wrack my brain on how to make the factors print with them. Any help would be greatly appreciated!!
Here is what i have so far.
#include <iostream>
using namespace std;
void perfect(int);
int main()
{
for(int number=2; number <= 10000 ; number++)
perfect(number);
system("pause");
return 0;
}
void perfect(int number){
int total = 0;
int i = 1;
int saveNum = 0;
for (i = 1; i < number; i++)
{
if (number % i == 0)
total += i;
}
if (number == total)
cout << number << endl;
}
this prints out
6
28
496
8128
I just cant seem to figure out how to get the factors to save in the function so i can print them with their perfect numbers.
Thanks!!