Average, Factorial and Fibonacci using LISP
Average
(defun average(n1 n2)
(setq avg (/ (+ n1 n2) 2))
)
Factorial
(defun factorial(n)
(if(= n 0 ) 1
(* n (factorial(- n 1)))
)
)
Fibonacci
(defun fibonacci()
(format t "Enter the limit : ")
(setf n(read))
(format t "Fibonacci series : ")
(format t "0 1")
(setf a 0)
(setf b 1)
(do ((i 3(+ i 1))) ((> i n))
(setf c (+ a b))
(format t " ~d" c)
(setf a b)
(setf b c)
)
)
0 comments: