Write a Prolog program to implement sumlist(L, S) so that S is the sum of a given list L.

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

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...