### Generation of Fibonacci Series - Recursion & Iteration -LISP

Program:
;;FIBONACCI SERIES
(defun fib(n)
(setf a 0 b 1)
(format t "~&<<<Generation of Fibonacci series with ~D terms>>>~&1.Iterative method~&2.Recursive method~&Enter your choice:" n)
(setf x (read))
(cond
((= n 1) (print a))
((= n 2) (print a)(print b))
((> n 2) (if (= x 1)
(fib1 n))
(if (= x 2)
(do ((i 0 (+ i 1))) ((= i n))
(print (fib2 i)))))
)
)
(defun fib1(n)
;Iterative method
(print a)(print b)
(do((i 2 (+ i 1))) ((= i n))
(setf c (+ a b))
(print c)
(setf a b b c))
)
(defun fib2(n)
(cond
((= n 0) 0)
((= n 1) 1)
((> n 1)(+ (fib2 (- n 1)) (fib2 (- n 2))))
;Recursive method
)
)

Output:
Break 2 [3]> (load 'f.lsp)
;;  Loading file f.lsp ...
;;  Loaded file f.lsp
T
Break 2 [3]> (fib 5)
<<<Generation of Fibonacci series with 5 terms>>>
1.Iterative method
2.Recursive method
Enter your choice:1

0
1
1
2
3
NIL
Break 2 [3]> (fib 5)
<<<Generation of Fibonacci series with 5 terms>>>
1.Iterative method
2.Recursive method
Enter your choice:2

0
1
1
2
3
NIL
Break 2 [3]>

#### 7 comments:

1. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

2. Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
Best Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram

3. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.

Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

4. Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read  about their market situation nowadays.
python Course in Pune
python Course institute in Chennai
python Training institute in Bangalore

5. This comment has been removed by the author.

6. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Python Training in Electronic City