LISP
LISP code for the above problem-
(defun read-side (side) (format t "Enter a value for side ~d: ~%" side) (read)) (defun triangle-p (a b c) (and (< a (+ b c)) (< b (+ a c)) (< c (+ a b)))) (defun equilateral-p (a b c) (= a b c)) (defun isoceles-p (a b c) (or (= a b) (= b c))) (defun status-message (message a b c) (format t "The shape ~d,~d,~d ~a ~%" a b c message)) (defun classify-triangle (a b c) (cond ((not (triangle-p a b c)) nil) ((equilateral-p a b c) 'equilateral) ((isoceles-p a b c) 'isoceles) (t 'triangle)))
(let* ((a (read-side 1)) (b (read-side 2)) (c (read-side 3)) (triangle-type (classify-triangle a b c))) (format t "classify triangle says ~a ~%" triangle-type) (cond ((eq 'equilateral triangle-type) (status-message "is an equilateral triangle." a b c)) ((eq 'isoceles triangle-type) (status-message "is an isoceles triangle." a b c)) ((eq 'triangle triangle-type) (status-message "is a "Scalene triangle." a b c)) (t (status-message "is not a triangle." a b c))))
If the answer helped then please upvote.And for any
queries, please comment.
Get Answers For Free
Most questions answered within 1 hours.