View difference between Paste ID: h61E3gE1 and HZrUN02k
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/gcl -f
2
3-
(defun printResult ( a b c x)
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-
(defun calcX (a b c)
21+
22
		)
23
	)
24
)
25
26
(defun calc-double-x (a b d)
27
	(list 
28
		( / (+ b (sqrt d)) (* 2 a))
29-
			(setq x 
29+
		( / (- b (sqrt d)) (* 2 a))
30-
				(list 
30+
31-
					( / 
31+
32-
						(+ b (sqrt d)) 
32+
33-
						(* 2 a)
33+
(defun calc-single-x (a b)
34-
					)
34+
	(list 
35-
					( / 
35+
		(/ (- b) (* 2 a))
36-
						(- b (sqrt d)) 
36+
37-
						(* 2 a)
37+
38-
					)
38+
39-
				)
39+
(defun calc-x (a b c)
40
	(let
41
		(
42-
				(setq x 
42+
43-
					(list 
43+
44-
						(/ 
44+
45-
							(- b)
45+
46-
							(* 2 a)
46+
47-
						)
47+
			(calc-double-x a b d)
48-
					)
48+
49-
				)
49+
				(calc-single-x a b)
50-
				(setq x () )
50+
				nil
51
			)
52
		)
53-
		x
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-
		(format t "a=")
67+
		(setf b (read-int "b="))
68-
		(setf a (read))
68+
		(setf c (read-int "c="))
69-
		(format t "b=")
69+
		(print-result a b c (calc-x a b c))
70-
		(setf b (read))
70+
71-
		(format t "c=")
71+
72-
		(setf c (read))
72+
73-
		(setf x (calcX a b c))
73+
74-
		(printResult a b c x)
74+
75
(bye)