Show F(n) of the Algorithm sequence of Fibonacci

Asked

Viewed 167 times

-3

I need to know the last term of the Fibonacci sequence, I’ve done it to show all the terms, but I need you to show me the last I’m using the Visualg

Algoritmo "Fibonacci"
Var
   v1, v2, v3, limite, cont: inteiro
Inicio
      escreval("Digite um limite:")
      leia(limite)
      v1 <- -1
      v2 <- 1
      cont <- 0
      
      enquanto cont< limite faca
            v3 <- v1 + v2
            v1<- v2
            v2 <- v3
            escreva(v3)
            cont <- cont+1
      fimenquanto
Fimalgoritmo

1 answer

0

Considering that all your code is correct, to print only the last value, you just need to take the command from inside the loop and put it after the loop. With this, you will only print the final result:

...
      enquanto cont< limite faca
            v3 <- v1 + v2
            v1<- v2
            v2 <- v3
            cont <- cont+1
      fimenquanto

      escreva(v3)
...

Browser other questions tagged

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