+ 1

Why my output show 1. I want to print perfect no between 1 to 1000???????

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

14th Aug 2018, 1:54 AM
Veeru
Veeru - avatar
3 odpowiedzi
+ 5
change line 7 to: for(int j=1;j<i;j++) a number is always dividable by itself, but that shouldn't be in it's sum.
14th Aug 2018, 2:53 AM
John Wells
John Wells - avatar
0
I is 1. S is 1. you print 1. I is 2. 2%1==0 s=1 2%2==0 s=3 No print I is 3. 3%1==0 s=1 3%2==1 s=1 3%3==0 s=4 No print. and the numbers keep groing
14th Aug 2018, 2:53 AM
Amir Galanty
Amir Galanty - avatar
0
Veerendra Kushwaha In 7th line remove <= nd put only < as we know that the number always divisible by itself but we study that In program perfect number are those in which sum of their factor excluding itself is equal to d that number!!!! But if u hve to do with this only then In line 15 i.e.if(s==i) // divide s by 2 so it wll work fine // hope u get it
14th Aug 2018, 3:54 AM
Harsh Agrawal
Harsh Agrawal - avatar