The second order equation: Ax2 + Bx + C - back to content

	       	?- start.
	        Input the coefficients:
        	A= 1.
	        B= -3.
        	C= 2.
	     	Solutions are x1= 2 x2= 1
	        Do you want to continue(y/n)? n.

start:- reads(A,B,C),solve(A,B,C),!,continue. reads(A,B,C):- write('Input the coefficients:'),nl, write('A='),read(A),write('B='),read(B),write('C='),read(C). delta(A,B,C,R):- D is (B*B-4*A*C),D >= 0,R is sqrt(D). solve(A,B,C):- A=\=0,delta(A,B,C,R), X1 is (-B+R)/(2*A), X2 is (-B-R)/(2*A), write('Solutions are '), write('x1= '),write(X1),write(' x2='),write(X2),nl. solve(A,B,C):- A=0,X is (-C/B), write('Equation is order I. Solution is: '),write(X),nl. solve(A,B,C):- delta(A,B,C,R),R=0,X is (-B/(2*A)), write('Has one solution: '),write(X),nl. solve(A,B,C):- write('No solutions.'),nl. continue:- write('Do you want to continue(y/n)? '), read(X),(X=y;X=ya;X=yes),start.