18.Write a Prolog program to implement maxlist(L, M) so that M is the maximum number in the list.
%Prolog program to implement maxlist(L, M)
% below maxlist function is not predefined you can use any name as function
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
No comments:
Post a Comment