Transforming algorithmism for visualg

Asked

Viewed 79 times

0

I’m starting to study algorithms, and to make it easier I try to bring all the algorithms to visualg.

I’m with an example algorithm but I’m not able to turn to the visualg anyone can help?

I know that "size(phrase)" I switch to Compr(phrase) that will give me the number of characters of the sentence. The problem is that I can’t 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
  • My mind is not fresh for Visualg. PARA , You seem to have forgotten the input instruction after calling the Compr(F) function. Repeat Commands

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 that.

Browser other questions tagged

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