1
I am doing the program of the following exercise:
Create an algorithm that reads the lower and upper bounds of a range and print all odd numbers in the open range and its sum (USE THE FOR). Suppose the entered data is for a decreasing interval.
My question is, how do I make him not display the numbers typed in? Why should I print the range opened, and in this, it should not display the numbers typed.
algoritmo "APS08"
var
inf, sup, soma:inteiro
i:inteiro
inicio
escreva("Digite o limite inferior: ")
leia(inf)
escreva("Digite o limite superior: ")
leia(sup)
para i de inf ate sup faca passo -1
se (i%2 = 1) entao
escreva(i)
soma <- soma + i
fimse
fimpara
escreval("")
escreval("Soma: ",soma)
fimalgoritmo
Can someone explain to me how I do?
[RESOLUTION]
algoritmo "APS08"
var
inf, sup, soma:inteiro
i:inteiro
inicio
escreva("Digite o limite inferior: ")
leia(inf)
escreva("Digite o limite superior: ")
leia(sup)
para i de sup-1 ate inf-1 passo -1 faca
se (i%2 = 1) entao
escreva(i)
soma <- soma + i
fimse
fimpara
escreval("")
escreval("Soma: ",soma)
fimalgoritmo
how so "do not display typed numbers"? wants to hide the command
leia
? How will you know what is being typed? If you want to take it off the screen later, just use the commandlimpatela
– Ricardo Pontual
No friend. Suppose the lower limit is 5 and the upper limit is 10. It will display all odd ones from 5 to 10 (5,7,9,11,13,15,17,19,21,23,25). The 5 and 25 should not appear. Do you understand? And should still be showing in descending order.
– tspereirarj
I get it, you can treat it on
para
, do not start frominf
butinf+1
and the same idea inate
, and if you want to reverse the inveta order also where thepara
– Ricardo Pontual
I made the change, it was
para i de inf+1 ate sup-1 passo -1
and solved the problem. As for the descending order, nothing. When I reversed the order, it stopped displaying.– tspereirarj
If you reverse the order, you also need to reverse the step:
para i de sup-1 ate inf+1 passo 1
– Ricardo Pontual
I already found the problem. That good old "error between the chair and the monitor". I appreciate your help, and I will edit the post with the resolution.
– tspereirarj
you can post the solution as the answer which is most correct
– Ricardo Pontual
Okay. In the next posts, I’ll do it. Thank you :)
– tspereirarj