Answer
Without Recursion
-------------------
(defun pow( )
(setf m(read))
(setf n(read))
(setf c 1)
(dotimes (i n)
(setf c ( * c m))
)
Expln:
Every lisp program will start a symbol '(' .
1) Define a function named 'pow'
2) Read 'm' variable
ie; scanf in C
3) Read 'n' variable
4) Initialise c=1
5) For loop
ie; in C, for(i=0;i<n;i++)
'dotimes' only for increment operations.
For decrementing......use another method for 'For-loop'..
(loop for ...) refer this
(loop for ...) refer this
6) Set c=c * m
In LISP,
We will use prefix notation.
ie; why we using
(* c m )
No comments:
Post a Comment