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 commentaire

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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Simulink dans Centre d'aide et File Exchange

Commenté :

Rik
le 14 Avr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by