1
I’m solving the following exercise:
Write an algorithm that averages the numbers typed by the user, if they are even. Finish reading if the user type zero (0)
However, when I type 0 to finish, it is counting 0 as even number, and this dividing by a number more.
algoritmo "semnome"
var
n,np,m,nnp:real
inicio
repita
escreval ("entre com um numero")
leia (n)
se n%2=0 entao
np<-np+1
nnp<-nnp+n
fimse
ate n=0
m<- nnp/np
escreval ("a media dos numeros é",m)
fimalgoritmo
Add a
e n diferente de 0
at these
.– Marcelo Shiniti Uchimura
The different operator is
<>
; therefore, adde n <> 0
at these
– Marcelo Shiniti Uchimura