Here is the code to print all the perfect numbers from 1-6, but loop only works once and prints only 1. Please specify the error in the code.
Basic Doubt in Perfect Number Question
Please share your code, you forgot to share your code.
Check now =>
If we do in the divisor_sum function, that run the loop from i=1 to i<=sqrt(num), then also it should print the same, So what is wrong in this one? Because doing so it is printing only 1 as output. Please Do resolve this as well.
Get this with an example, 28 is perfect number. Sqrt(28) will be 5, whereas when you will find divisor of 28, they will be 2,2,7. So 7 won’t be included while running the loop. Same is for 6, sqrt(6) will be 2. So 3 won’t be included. So it won’t work.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.