I\'ve BEEN TRYING TO GET A FIX ON THE NUMBERS THIS PROGRAM IS USING TO COMPARE T
ID: 3622439 • Letter: I
Question
I've BEEN TRYING TO GET A FIX ON THE NUMBERS THIS PROGRAM IS USING TO COMPARE TO DETERMINE IF THE NUMBER IS PERFECT OR NOT. Unfortunately I haven't been able to do so. Can someone help me out with a print routine for these factors? I tried but the routine printed out the the factors in a form I couldn't use. it was like 2,3,3,2 and i needed it to be like 6: 1,2,3. Any help would be greatly appreciated. Thanks![code]
#include <iostream>
using namespace std;
int main() {
int i=1;
int sum = 0;
int count=0;
int j;
while(count<44)
{
sum = 0;
for (int j = 1; j < i; j++) { //check every number from 1 to i-1 for divisibility
if (i % j == 0) // if j divides evenly into i
sum += j; //add j (the divisor) to the sum
}
if (sum == i)
//if the sum of the divisors equals the number
{cout << i << endl; //print out the perfect number
count++;
}
i++;
}
cout << "DONE!" << endl;
system("pause");
return EXIT_SUCCESS;
}
[/code]