Created
August 4, 2019 12:29
-
-
Save vlad-bezden/42a7f49b5c87cd9f9199bbe844a8ccb7 to your computer and use it in GitHub Desktop.
Fibonacci number calculator in go
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 ( | |
"flag" | |
"fmt" | |
"time" | |
) | |
var n int | |
func fib(n int) int { | |
for n > 1 { | |
return fib(n-1) + fib(n-2) | |
} | |
return n | |
} | |
func main() { | |
startTime := time.Now() | |
num := fib(n) | |
fmt.Printf("Fibonacchi number for %d is %d\n", n, num) | |
fmt.Println("Exec time:", time.Since(startTime)) | |
} | |
func init() { | |
flag.IntVar(&n, "n", 1, "Fibonacci number to be found") | |
flag.Parse() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment