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

Function Iterative

math/factorial/factorial.go:20–29  ·  view source on GitHub ↗

Iterative returns the iteratively brute forced factorial of n

(n int)

Source from the content-addressed store, hash-verified

18
19// Iterative returns the iteratively brute forced factorial of n
20func Iterative(n int) (int, error) {
21 if n < 0 {
22 return 0, ErrNegativeArgument
23 }
24 result := 1
25 for i := 2; i <= n; i++ {
26 result *= i
27 }
28 return result, nil
29}
30
31// Recursive This function recursively computes the factorial of a number
32func Recursive(n int) (int, error) {

Callers 1

Problem15Function · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected