-
-
Notifications
You must be signed in to change notification settings - Fork 6
Fibonacci
Vilsol edited this page Jan 7, 2021
·
1 revision
A simple program that outputs the n
'th number in Fibonacci sequence.
package main
import "github.com/Vilsol/go-mlog/m"
func main() {
println(fib(45))
m.PrintFlush("message1")
}
func fib(n int) int {
if n <= 1 {
return n
}
grandparent := 1
parent := 2
me := parent
for i := 3; i < n; i++ {
me = parent + grandparent
grandparent = parent
parent = me
}
return me
}