Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def factorial_recursive(n):
- """
- Computes the factorial of a non-negative number n (using recursion)
- """
- if n == 0:
- return 1
- return n * factorial_recursive(n - 1)
- def factorial_iterative(n):
- """
- Computes the factorial of a non-negative number n (using iteration)
- """
- result = 1
- if n == 0:
- return 1
- for num in range(1, n + 1):
- result *= num
- return result
- factorial_recursive(15)
- factorial_iterative(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement