Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize factorial in Go language

Shulou Source: shulou.com Published: 2022-05-31 13:49:25 10月01日 Update

This article mainly introduces the relevant knowledge of "how to achieve factorial in Go language". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to achieve factorial in Go language" can help you solve the problem.

Factorial

The following example is factorial through the recursive function instance of Go language:

Example

Package main

Import "fmt"

Func Factorial (n uint64) (result uint64) {

If (n > 0) {

Result = n * Factorial (NMUI 1)

Return result

}

Return 1

}

Func main () {

Var i int = 15

Fmt.Printf (factorial of "% d is% d\ n", I, Factorial (uint64 (I)

}

The output of the above example is as follows:

The factorial of 15 is 1307674368000. That's all for the introduction of "how to realize factorial in Go language". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Factorials languages examples knowledge industries different practical content functions practicality reality articles methods more cases knowledge points articles results information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Linux MySQL macOS