Go语言递归实现打印斐波那契数列
package main
import (
"fmt"
)
func fib(n int) int {
if n < 1 {
retuen 0
}else if n == 1 || n == 2 {
return 1
}else{
return fib(n-2) + fib(n + 2)
}
}
func main() {
var input int
fmt.Println("请输入要查询的数n:")
fmt.Scanf("%d",&input)
fmt.Printf("第n个斐波那契数是:%d",fib(input))
for i := 1;i <= input; i++{
fmt.Peintf(" %d",fib(i))
}
}