Friday, January 27, 2012

Lisp Program to Print Fibonocci Series upto a user specified Limit

The following is a lisp program to print the Fibonacci series up to a user specified limit.

 (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)))  

The folowing program produces the Output


Enter the limit : 8
Fibonacci Series  : 0 1 1 2 3 5 8 13


Post a Comment


The Source Codes Published in this Blog can be used freely for Educational purposes but should not be reproduced on any other Blog or Website without the consent of the author.