In: Computer Science
Use logical language Prolog. Use SWISH (SWI Prolog for Sharing)
Write a Prolog program that finds the maximum of a list of numbers. Submission file should include a screenshot with tracing a program execution when a list only has 2 members and execution without tracing when a list has 8 elements.
%max in list
maxlist([X|L],M):- max(L,X,M). % call accumulator to find max
max([],X,X).
max([X|L],C,M):- C =< X ,
M1 is X,
max(L,M1,M).
max([_|L],C,M):- max(L,C,M).
% tracing and output with 2 elements
% ouput with 8 elements
/* PLEASE UPVOTE */