3
algoritmo "numeros_perfeitos"
var
c, n:inteiro
nv, np, npv:real
inicio
para n <- 1 ate 100 faca
para c <- 1 ate n faca
se n % c = 0 entao
nv <- n / c
se nv < n entao
np <- nv + np
fimse
fimse
fimpara
se np = n entao
escreva(np)
fimse
np <- 0
nv <- 0
fimpara
fimalgoritmo
I wrote this code for this exercise:
Write an algorithm that generates and writes the first 4 numbers perfect. A perfect number is one that is equal to the sum of its divisors. Ex: 6 = 1+2+3; 28= 1+2+4+7+14.
But he hangs how much I put from n to 10000 I did something wrong? And why does he perform many cycles in the internal structure (I think it is 100000 cycles)? My logic was bad?
Thank you very much I understood, it is normal to make this mistake and I was very stupid?
– AleKing
It’s part of learning, the important thing is to always try to grow. (:
– Felipe Avelar
Thanks for the help.
– AleKing