Advertisement
Guest User

Untitled

a guest
Dec 7th, 2013
503
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 (if (< b 0) "" "+"))
  12.             (cSign (if (< c 0) "" "+"))
  13.         )
  14.         (format t
  15.             "For ~A*x^2 ~A ~A*x ~A ~A = 0 You can find ~A.~%"
  16.             a
  17.             bSign b
  18.             cSign c
  19.             x
  20.         )
  21.     )
  22. )
  23.  
  24. (defun calc-double-x (a b d)
  25.     (list
  26.         ( / (+ b (sqrt d)) (* 2 a))
  27.         ( / (- b (sqrt d)) (* 2 a))
  28.     )
  29. )
  30.  
  31. (defun calc-single-x (a b)
  32.     (list
  33.         (/ (- b) (* 2 a))
  34.     )
  35. )
  36.  
  37. (defun calc-x (a b c)
  38.     (let
  39.         (
  40.             (d (- (* b b) (* 4 a c)))
  41.             (x 0)
  42.         )
  43.         (if (> d 0)
  44.             (calc-double-x a b d)
  45.             (if (eql d 0)
  46.                 (calc-single-x a b)
  47.                 nil
  48.             )
  49.         )
  50.     )
  51. )
  52.  
  53. (defun square ()
  54.     (format t "a*x^2 + b*x + c = 0~%")
  55.    
  56.     (let
  57.         (
  58.             (a (read-int "a="))
  59.             (b (read-int "b="))
  60.             (c (read-int "c="))
  61.         )
  62.         (print-result a b c (calc-x a b c))
  63.     )
  64. )
  65.  
  66.  
  67. (square)
  68. (bye)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement