Go language recursive function

Source: Internet
Author: User
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>
1 5040

Go language recursive function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.