Transforming algorithm for visual

0

I'm starting to study algorithms, and to facilitate I try to take all the algorithms to the visualg.

I'm having an example algorithm but I can not transform it to visualg can anyone help?

I know that "size (phrase)" I change to Compr (phrase) that will give me the number of characters in the sentence. The problem is that I can not call this function.

Algorithm:

função inverte(entradas: frase)
início
    resultado <- frase
    para i <- 1 até tamanho(frase)/2 faça
        aux <- frase[i]
        resultado[i] <- frase[tamanho(frase)-i+1]
        resultado[tamanho(frase)-i+1] <- aux
    próximo i
fim  

O que fiz até agora foi:

algoritmo "Teste"

var
    F: caracter

Funcao inverte(): caracter
var

    frase: vetor [1..20] de caracter
    i, j: inteiro

inicio

     Para i de 1 ate Compr(F) faca
       frase[i] <- Copia(F; i, 1)
      FimPara
      j <- Compr(F)
      Para i de 1 ate Compr(F) faca
         Escreva (frase[j])
         j <- j - 1
      FimPara
FimFuncao
inicio

     Escreva ("entre como a palavra: ")
     Leia (F)
     inverter(F)


fimalgoritmo
    
asked by anonymous 10.10.2018 / 22:38

1 answer

1

After hitting a lot I managed to solve. The problem is that the function needs a return variable and I was not doing it.

    
11.10.2018 / 22:26