Регистрация | Войти
Lisp — программируемый язык программирования
for trex6
Автор: ugoday - 2013-12-07T13:00:43.000000+04:00
(defun read-int (text)
        (format t text)
        (read)
)


(defun print-result (a b c x)
        (let ((bSign (if (< b 0) "" "+"))
              (cSign (if (< c 0) "" "+"))
)

                (format t "For ~A*x^2 ~A ~A*x ~A ~A = 0 You can find ~A.~%" a bSign b cSign c x)
)
)


(defun calc-double-x (a b d)
  (list ( / (+ b (sqrt d)) (* 2 a)) ( / (- b (sqrt d)) (* 2 a)))
)


(defun calc-single-x (a b)
  (list (/ (- b) (* 2 a)))
)


(defun calc-x (a b c)
  (let ((d (- (* b b) (* 4 a c)))
        (x 0)
)

    (if (> d 0) (calc-double-x a b d)
        (if (eql d 0) (calc-single-x a b)
            nil
)
)
)
)


(defun square ()
  (format t "a*x^2 + b*x + c = 0~%")
  (let ((a (read-int "a="))
        (b (read-int "b="))
        (c (read-int "c="))
)

    (print-result a b c (calc-x a b c))
)
)


(square)
(bye)
@2009-2013 lisper.ru