Skip to content

Instantly share code, notes, and snippets.

@Jason-cqtan
Created January 21, 2020 08:22
Show Gist options
  • Save Jason-cqtan/477851723c556b44e141c74bef057b56 to your computer and use it in GitHub Desktop.
Save Jason-cqtan/477851723c556b44e141c74bef057b56 to your computer and use it in GitHub Desktop.
斐波那契数列go版
package main
import (
"fmt"
"math"
)
func main() {
//返回10个斐波那契数列,todo 使用int,结果数字会越界
fibonacciIndex(10)
}
func fibonacciIndex(length int) {
slice := make([]int,length)
for i:=0;i<len(slice) ;i++ {
tem := 0
if i < 1 {
tem = 0
} else if i < 2 {
var sum = (i - 1) + (i - 2)
tem = int(math.Abs(float64(sum)))
slice[i] = tem
}else {
tem = slice[i-1] + slice[i-2]
slice[i] = tem
}
}
fmt.Println(slice)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment