Monday, July 17, 2023

15. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List using cut predicate.

 15. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List using cut predicate. 


maxlist([H],H).

maxlist([H|T],R):-

maxlist(T,M1),

 H>=M1,

 R is H,!.

maxlist([H|T],R):-

maxlist(T,M1),

 H<M1,

 R is M1.


OUTPUT:.

maxlist([1,20,2],X).

X = 20

 



No comments:

Post a Comment