2
I’m having trouble with the following question:
Create an M[21.10] matrix. Read 10 names (maximum 20 characters) and store in the first row of the matrix. After reading, decompose the names letter by letter and store them in the other lines of the matrix from the second. At the end, write the matrix.
My code was as follows:
algoritmo "Exercício 4"
var
m : vetor[1..21, 1..10] de caractere
nome : caractere
i, j : inteiro
inicio
i := 1
para j de 1 ate 10 faca
repita
escreva("Informe o nome: ")
leia(m[i, j])
se compr(m[i, j]) > 20 entao
escreval("Informe um nome com no máx. 20 caracteres.")
fimse
ate compr(m[i, j]) <= 20
fimrepita
fimpara
para i de 2 ate 21 faca
para j de 1 ate compr(m[1, j]) faca
escreval(copia(m[1, j], j, 1))
fimpara
fimpara
fimalgoritmo
I’m not being able to distribute the letters in the matrix, and the error in my code says that there’s a do missing in the 5th line from the bottom up, but the do is there.
Haven’t you asked that question already? (I was just reading it)
– Jéf Bueno
Actually I did this morning too, now I just corrected from "Vector" to "Matrix" in the title. But I asked again this afternoon showing the algorithm, not only asking for the explanation.
– Jow
Okay, this is not how it should be done. All publications can be edited when you feel like it. As the current publication is better than the other, keep this as it is. The other will be closed.
– Jéf Bueno
Ah, sorry. I could’ve sworn I deleted the other one.
– Jow
Relax, I’m downloading Visualg to test the code.
– Jéf Bueno
All right, thanks :)
– Jow
Related: https://answall.com/questions/206191/algoritmo-para-leitura-scripted https://answall.com/questions/206782/strings-em-matrix
– MarceloBoni