Repeat structure within the selection in visualg

Asked

Viewed 190 times

-1

Function :Write a program that creates an initially zeroed vector and insert a value into the vector at an informed position. For example, for the empty vector v = { }, position 4 and value 10, the program must generate v={ , , ,10}. If the position is 2 and the value 5, the vector will be v = { , 5, ,10}. And so, successively. If the position is occupied, the values must be moved in order to leave the chosen position free for the insertion of the new value, the vector will be v = { , 23, 5, ,10}. Show vector after insertions.

stop<-"s"
for 1 to 5 knife count
x[cont]<-0
firming
while (stop="s") knife
type("Type a position up to 4 that you want to change: ")
read (posi)
while (posi>4) knife
type("Type a position up to 4 that you want to change: ")
read (posi)
fimenquanto
type("Enter the value you want to enter in this position: ")
read (value)
posi2<-posi+1
if (x[posi]=0)
x[posi]<-value
or
for container from 5 to posi2 knife
cont2<-(cont-1)
x[cont]<-x[cont2]
firming

x[posi]<-value
film
repeat
write("Do you wish to continue? (’S'/'N'): ")
read (stop)
ate (stop="s") or (stop="n")
fimenquanto
typing("==============Result of changes=================")
for 1 to 5 knife count
type (x[cont]," under ",cont)
firming

inserir a descrição da imagem aqui

this part in bold and the part in red in the image visualg does not read, it jumps straight pro "x[posi]<-value" below the string and I need this repetition to change the position values. I did so, someone knows if it is incorrect or if there is another way to do this exercise??

1 answer

0

PROBLEM SOLVED

for 5 to 2 container step-1 knife
cont2<-(cont-1)
x[cont]<-x[cont2]
firming

was the command step-1 that was missing, with it the structure for can count in countdown order.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.