package main
import (
"fmt"
)
func fibo(n int) []uint64 {
fiboSlice := make([]uint64, n)
fiboSlice[0] = 1
fiboSlice[1] = 1
for i := 2; i < n; i++ {
fiboSlice[i] = fiboSlice[i-1] + fiboSlice[i-2]
}
return fiboSlice
}
func main() {
var n int
fmt.Println("输入你想得到第几个斐波那契数列")
fmt.Scanln(&n)
res := fibo(n)
fmt.Println(res)
}
测试一下
$ go run main.go
输入你想得到第几个斐波那契数列
9
[1 1 2 3 5 8 13 21 34]