Monday, July 17, 2023

12. Write a Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List.

  12. Write a Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List. 


sumlist([],0).

 

sumlist([H|T],R):-

sumlist(T,R1),

  R is H+R1.

OUTPUT:

sumlist([6,9,70],X).

X = 85


No comments:

Post a Comment