Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
will it recur fibonacci
package main
import (
"fmt"
"time"
)
func fibonacci(n int) int {
var a int
if n < 2 {
a = 1
} else {
a = fibonacci(n - 2) + fibonacci(n - 1)
}
return a
}
func main() {
time1 := time.Now()
fmt.Println(fibonacci(40))
time2 := time.Now()
elapsed := float32(time2.Sub(time1)) / 1e6
fmt.Printf("Elapsed time: %.4f milliseconds\n", elapsed)
}
@moderation

This comment has been minimized.

Copy link
Owner Author

commented Dec 2, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.