在Go编程中, 从函数内部调用相同的函数称为递归。将问题分解为多个任务总是一个好主意。让我们看一个使用递归在Go编程中计算阶乘值的程序。
递归示例:阶乘数
package main
import (
"fmt"
)
func main() {
fmt.Println(factorial(5))
}
func factorial(num int ) int{
if num == 0{
return 1
}
return num*factorial(num-1)
}
输出:
120
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_50035.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57