Last active
March 8, 2020 12:03
-
-
Save rxrav/b29f217e1c593fcb89c055f7e1a31d5b to your computer and use it in GitHub Desktop.
Fibonacci series implementation using recursion technique in Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
var rCounter int | |
func fibRec(i int) int { | |
rCounter++ | |
if i == 1 { | |
return 0 | |
} else if i == 2 { | |
return 1 | |
} else { | |
return fibRec(i-1) + fibRec(i-2) | |
} | |
} | |
func main() { | |
fmt.Println(fibRec(16)) | |
fmt.Println("Called function", rCounter, "times") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment