CL-USER> (defun sum-of-two(a b c)
(cond ((if (>= a b c) ( + a b)))
((if (>= a c b) ( + a c)))
((if (>= b c a) ( + b c)))
((if (>= b a c) ( + b a)))
((if (>= c a b) ( + c a)))
((if (>= c b a) ( + c b)))))
SUM-OF-TWO
CL-USER> (sum-of-two 3 2 5)
8
CL-USER> (sum-of-two 1 2 3)
5
CL-USER> (sum-of-two 5 4 3 )
9
CL-USER> (sum-of-two 3 5 4)
9
CL-USER> (if ( < a b) a b)
4
CL-USER> (if ( < a b) a b)
3
优化一下 :
CL-USER> (DEFUN SUM-OF-TWO-1(A B C)
(cond ((if (and (> a c) (> b c))(+ a b)))
((if (and (> b a) (> c a))(+ b c)))
( (+ a c))))
SUM-OF-TWO-1
CL-USER> (sum-of-two-1 3 2 5)
8
CL-USER> (sum-of-two-1 1 2 3)
5
CL-USER> (sum-of-two-1 5 4 3)
9
CL-USER> (sum-of-two-1 3 5 4)
9
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/133735/viewspace-749603/,如需转载,请注明出处,否则将追究法律责任。