MCPcopy Create free account
hub / github.com/mmcgrana/gobyexample / fact

Function fact

examples/recursion/recursion.go:11–16  ·  view source on GitHub ↗

This `fact` function calls itself until it reaches the base case of `fact(0)`.

(n int)

Source from the content-addressed store, hash-verified

9// This `fact` function calls itself until it reaches the
10// base case of `fact(0)`.
11func fact(n int) int {
12 if n == 0 {
13 return 1
14 }
15 return n * fact(n-1)
16}
17
18func main() {
19 fmt.Println(fact(7))

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected