Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been trying to find the location of the factors making the perfect numbers

ID: 3622535 • Letter: I

Question

I've been trying to find the location of the factors making the perfect numbers o I can print them along with thier sum. thus showing how the sum of the factors are equal to the perfect number but I can fnd the factors to display. ie.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]

Explanation / Answer

A perfect number is the sum of its factors. Look at the code: there's a variable named sum. sum accumulates from j. Therefore, j will have the factors you're looking for. j is a factor if j%i == 0.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote