14.Write a Prolog program to implement sumlist(L, S) so that S is the sum of a given list L.
% Write a Prolog program to implement sumlist(L, S) so that S is the sum of a given list L.
% below sumlist function is not predefined you can use any name as function
sumlist([],0).
sumlist([H|T],S):- sumlist(T,S1),S is H+S1.
% Output
No comments:
Post a Comment