Write a Prolog program to implement maxlist(L, M) so that M is the maximum number in the list.

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

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...