please help with this code . i was trying to write a code about perfect number ,
ID: 3613726 • Letter: P
Question
please help with this code . i was trying to write a code aboutperfect number , but part of my result isnot correct and i was trying since to detect this error .the perfect numbers is between 1 to 10000.the result should be 6 , 28 ,496,8128.but my output shows 6,24,28,496,2016,8128,8190which is incorrect.this is my code below
#include <iostream>
using namespace std;
int main()
{
for(int j = 2; j <= 10000; j = j+1)
{
int sum = 0;
for(int i = 1; i <= 10000;i=i+1)
{
if(j % i == 0 )
{
sum += i;
if(sum == j)
{
cout <<"The number is " << sum<<" ";
}
}
}
}
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks your loops are nested incorrectly inaddition your i loop should go toRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.