3
I’m using Portugol Studio to study algorithms in Portuguese. And I’m having a hard time with a question that the teacher passed.
the question is as follows:
Develop an algorithm that requires the user to enter 10 numbers any integers. Print the sum of the typed numbers.
My algorithm is like this:
programa
{
inteiro cont=0, numero, soma=0
funcao inicio()
{
enquanto (cont<3)
{
cont++
escreva ("Digite um número inteiro: ")
leia (numero)
limpa()
}
soma = soma+numero
escreva ("\nA soma é: ", soma)
}
}
But I don’t get the exact sum back.
---------- Boy! Thanks guys! I was breaking my head here with this sum... Something so simple... Nor did I realize that the variable had to stay inside the loop! So she keeps adding the values... Vlw personal!
– Sandson Costa
I just don’t understand why its loop goes from 0 to 2 if the exercise asks to elaborate an algorithm where the user enters with 10 integers.
– Reginaldo Rigo
It’s because I reduced the size to get the result... so I don’t have to take the test with the 10 values! Actually the teacher asked with 100 values! then I decrease to 10 and consequently to 2 hahaha
– Sandson Costa