MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Recursive

Function Recursive

math/factorial/factorial.go:32–41  ·  view source on GitHub ↗

Recursive This function recursively computes the factorial of a number

(n int)

Source from the content-addressed store, hash-verified

30
31// Recursive This function recursively computes the factorial of a number
32func Recursive(n int) (int, error) {
33 if n < 0 {
34 return 0, ErrNegativeArgument
35 }
36 if n <= 1 {
37 return 1, nil
38 }
39 prev, _ := Recursive(n - 1)
40 return n * prev, nil
41}
42
43// UsingTree This function finds the factorial of a number using a binary tree
44func UsingTree(n int) (int, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected