1.递归算法实现99乘法表
package main import ( "fmt") func main () { fmt.Println(table99(9)) } func middlep(a int) (res string) { fmt.Println("") return} func table99(i int ) (res string) { if i>=1 { table99(i-1) defer middlep(i) for j:=1;j<=i;j++ { fmt.Printf("%d*%d=%d\t",i,j,i*j) } } return}2.递归实现阶乘
package main import "fmt" func main() { fmt.Println(fib1(4)) } func fib1(n int) (res int) { if n == 0 { res = 1 } else { res = n * fib1(n-1) } return}3.递归实现斐波那契数列
package main import "fmt" func main () { for i:= 1; i<=10 ;i++ { fmt.Println(i, fib(i)) } } func fib(n int) (res int) { if n <=1{ res = n } else { res = fib(n-1) + fib(n-2) } return}