Advertisement
Guest User

Untitled

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