Iterative returns the iteratively brute forced factorial of n
(n int)
| 18 | |
| 19 | // Iterative returns the iteratively brute forced factorial of n |
| 20 | func 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 |
| 32 | func Recursive(n int) (int, error) { |