Determining perfect numbers from 1 - 1000

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!

1 Comment

It seems to work just fine when I test it. It matches the list on Wikipedia.
What is your question?

Sign in to comment.

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Asked:

on 14 Apr 2020

Commented:

Rik
on 14 Apr 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!