The Math
f(0) = 1 for n = 0
f(n) = (n * factorial(n-1)) for n>0
The Function
(defun factorial (n)
(if (= n 0) 1 ( * n (factorial (- n 1)) ))
)
The Output
> factorial 3 = 6
f(0) = 1 for n = 0
f(n) = (n * factorial(n-1)) for n>0
The Function
(defun factorial (n)
(if (= n 0) 1 ( * n (factorial (- n 1)) ))
)
The Output
> factorial 3 = 6
Comments
Post a Comment