1. 程式人生 > >golang 實現遞歸

golang 實現遞歸

lan 執行 build document ola 遞歸 print project 結果

package main

import "fmt"

func Recursive(n int) int {
if n == 0 {
return 1
}
//相當於10987654321
return n
Recursive(n-1)
}
func main() {
fmt.Println(Recursive(10))
}

執行結果:
sf@SFdeMacBook-Pro  ~/Documents/project/src/test  go build Recursive.go
sf@SFdeMacBook-Pro  ~/Documents/project/src/test  ./Recursive
3628800

golang 實現遞歸