Advertisement
Guest User

Untitled

a guest
Dec 7th, 2013
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/gcl -f
  2.  
  3. (defun read-int (text)
  4.     (format t text)
  5.     (read)
  6. )
  7.  
  8. (defun print-result ( a b c x)
  9.     (let
  10.         (
  11.             (bSign "+")
  12.             (cSign "+")
  13.         )
  14.         (if (< b 0) (setf bSign "") ())
  15.         (if (< c 0) (setf cSign "") ())
  16.         (format t
  17.             "For ~A*x^2 ~A ~A*x ~A ~A = 0 You can find ~A.~%"
  18.             a
  19.             bSign b
  20.             cSign c
  21.             x
  22.         )
  23.     )
  24. )
  25.  
  26. (defun calc-double-x (a b d)
  27.     (list
  28.         ( / (+ b (sqrt d)) (* 2 a))
  29.         ( / (- b (sqrt d)) (* 2 a))
  30.     )
  31. )
  32.  
  33. (defun calc-single-x (a b)
  34.     (list
  35.         (/ (- b) (* 2 a))
  36.     )
  37. )
  38.  
  39. (defun calc-x (a b c)
  40.     (let
  41.         (
  42.             (d 0)
  43.             (x 0)
  44.         )
  45.         (setf d (- (* b b) (* 4 a c)))
  46.         (if (> d 0)
  47.             (calc-double-x a b d)
  48.             (if (eql d 0)
  49.                 (calc-single-x a b)
  50.                 nil
  51.             )
  52.         )
  53.     )
  54. )
  55.  
  56. (defun square ()
  57.     (format t "a*x^2 + b*x + c = 0~%")
  58.    
  59.     (let
  60.         (
  61.             (a 0)
  62.             (b 0)
  63.             (c 0)
  64.             (x 0)
  65.         )
  66.         (setf a (read-int "a="))
  67.         (setf b (read-int "b="))
  68.         (setf c (read-int "c="))
  69.         (print-result a b c (calc-x a b c))
  70.     )
  71. )
  72.  
  73.  
  74. (square)
  75. (bye)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement