This is a creation in Article, where the information may have evolved or changed.
In programming languages, function func (Type a,......) Call the function itself directly or indirectly, the function is called a recursive function. A recursive function cannot be defined as an inline function.
In mathematics, the definition of a recursive function is as follows: For a function f (x), whose definition field is set a, then the function value f (x0) is determined by F (f (x0)) for a value in the a set, and F (X0) is called a recursive function.
Package <textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">Mainimport "FMT" This fact function calls itself until it reaches the base case of fact (0). Func fact (n int) int {if n = = 0 {return 1} return n * fact (n-1)}func main () {FMT. Println (Fact (7))}</textarea>
| 123456789101112 |
Package MainImport "FMT" This factfunction callsitselfuntilitreaches theBase Case offact(0).funcfact(N int) int { if N == 0 { return 1 } return N * fact(N-1)}funcMain() { FMT.Println(fact(7))} |
Output Result:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">5040</textarea>
Go language recursive function