0

I am trying to print all perfect number between a range but I am not getting desired output can someone can help me

https://code.sololearn.com/co30bw9Dg3R3/?ref=app

19th Apr 2021, 6:13 AM
Harsh Pratap Singh
Harsh Pratap Singh - avatar
2 Answers
+ 1
void perfect(void){ int count = 0; for ( int i = 1; i<=1000; i++ ){ for(int j =1; j<i; j++){ if(i%j==0){ count = count + j; } } if(count == i){ cout<<i<<endl; // this if is outside, only check the sum of divisors after you find all the divisors } count = 0; // resets the sum of divisors back to 0, preparing for the next number } } I changed a bit of your codes there. Please refer to the comments I wrote inside
19th Apr 2021, 6:27 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
Thanks bro now I get my desired result
19th Apr 2021, 10:06 AM
Harsh Pratap Singh
Harsh Pratap Singh - avatar