Determining perfect numbers from 1 - 1000
5 views (last 30 days)
Show older comments
I need to make a code where it determines the perfect numbers within 1 - 1000, and also displaying their factors to prove that they are perfect numbers. Can anyone please help me?
I've been looking up for clues and find myself in circles with this code I also searched for, which I also used as my basis:
function num = is_perfect(n)
i = 1;
factorsum = 0;
while i<= n-1
if rem(n,i) == 0
factorsum = factorsum + i;
end
i = i +1;
end
if n == factorsum
num = true;
else
num = false;
end
end
But apparently this doesn't answer the problem I have. I'm still trying to alter the code according to the given problem.
Thank you!
Answers (0)
See Also
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!