Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/gcl -f
- (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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement