Sunday, February 16, 2025

14. 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.

 

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.

% 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.

max2([H],H).
max2([H|T],R):-
 max2(T,M1),
 H>=M1,
 R is H,!.
max2([H|T],R):-
 max2(T,M1),
 H<M1, 
 R is M1.
% Output
Prolog program to implement maxlist(List,Max)
Prolog program to implement maxlist(List,Max) using cut predicate.

No comments:

Post a Comment

15. Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.

  Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list ...