Determining perfect numbers from 1 - 1000
Afficher commentaires plus anciens
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
le 14 Avr 2020
What is your question?
Réponses (0)
Catégories
En savoir plus sur Simulink dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!