11. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.
max([H|T],R):-
length(T,L),
L>0 -> ( max(T,R1), ( H > R1 -> R is H ; R is R1 ) ) ; R is H.
OUTPUT:
max([6,9,7],X).
X = 9
max([6,9,70],X).
X = 70
No comments:
Post a Comment