Prolog program to find the roots of the quadratic equation. - Artificial intelligence

No comments

  • program to find the roots of the quadratic equation.

Program


delta(A, B, C, D):- D is B*B - 4*A*C.
equation(A,B,C,X) :-
 delta(A,B,C,D1),
 (  D1 < 0
 -> X is 0
 ;  D1 =:= 0
 -> X is -B/2*A
 ;  X is -B-sqrt(D1)/2*A
 ).

Output

?- equation(1,2,3,X).
X = 0.
?- equation(1,4,3,X).
X = -5.0.
?- equation(1,4,4,X).

X = -2.

No comments :

Post a Comment