Prolog program to find the greatest variable among the three variable. - Artificial intelligence
- Write a program to find the greatest variable among the three variable
Program
max(P,Q,R):-P>Q,P>R,write('Larger
number is '),write(P).
max(P,Q,R):-P<Q,Q>R,write('Larger
number is '),write(Q).
max(P,Q,R):-R>Q,P<R,write('Larger
number is '),write(R).
max(P,Q,R):-P=Q,P<R,write('Larger
number is '),write(R).
max(P,Q,R):-P<Q,P=R,write('Larger
number is '),write(Q).
max(P,Q,R):-Q=R,P>Q,write('Larger
number is '),write(P).
max(P,Q,R):-P=Q,P=R,write('All
numbers are equal ').
max(P,Q,R):-P=Q,P>R,write('Larger
numbers are '),write(P),write(' and
'),write(Q).
max(P,Q,R):-P=R,Q<R,write('Larger
numbers are '),write(P),write(' and
'),write(R).
max(P,Q,R):-Q=R,P<R,write('Larger
numbers are '),write(R),write(' and
'),write(Q).
Output
?-
max(1,2,3).
Larger
number is 3
true
.
?-
max(2,2,2).
All
numbers are equal
true.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment