From 14377af2db42f749fb33b1855b854749c7b103ea Mon Sep 17 00:00:00 2001 From: Lincoln Ruteski Date: Wed, 27 Mar 2024 16:38:27 -0300 Subject: [PATCH] 14.4 funcoes recursivas --- .../funcao_recursiva.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 14-funcoes_avacadas/14.4-funcoes_recursivas/funcao_recursiva.go diff --git a/14-funcoes_avacadas/14.4-funcoes_recursivas/funcao_recursiva.go b/14-funcoes_avacadas/14.4-funcoes_recursivas/funcao_recursiva.go new file mode 100644 index 0000000..bf8eb6d --- /dev/null +++ b/14-funcoes_avacadas/14.4-funcoes_recursivas/funcao_recursiva.go @@ -0,0 +1,21 @@ +package main + +import "fmt" + +func fibonacci(posicao uint) uint { + if posicao <= 1 { + return posicao + } + + return fibonacci(posicao-2) + fibonacci(posicao-1) +} + +func main() { + posicao := uint(20) + + for i := uint(0); i < posicao; i++ { + fmt.Println(fibonacci(i)) + } + + fmt.Println(fibonacci(posicao)) +}