lisp
编程实例
Visual LISP
编程应用实例集
一、
计算类程序
1.
计算阶剩值
n! (
注意
:
采用了递归方式
)
(defun jsen (n)
(if (= n 0) 1 (* n (jsen (1- n)))));
3) 2.
迭代计算
(x,x,1,0
(defun ddai (x)
(setq x1 0 x2 x e 1.0e-5 i 0)
(while (> (abs (- x2 x1)) e) (setq x1 x2) (setq x2 (expt (+ x1 1) (/
1 3.0))) (setq i (1+ i)));while
(print "x=") (princ x2) (print "i=") (princ i)
(princ));end
23.
一元二次方程求解
() ax
,
bx
,
c,0
(defun px2 (a b c)
(setq d (- (expt b 2.0) (* 4 a c)))
(cond ((
((= d 0) (progn (setq x (/ b (* -2.0 a))) (prompt "\nOne root! x=")
(princ x)))
((> d 0) (progn (setq x1 (/ (- (sqrt d) b) (* 2.0 a)) x2 (/ (+ (sqrt
d) b) (* -2.0 a)))
(prompt "\nTwo root! x1=") (princ x1) (prompt " x2=") (princ
x2))));cond (princ));end