Write a Prolog program to find the sum of elements of a list

Aim: Write a Prolog program to find the sum of elements of a list.


Prolog Program Code:


domains
    X=integer
    l=integer*
predicates
   sum(l,X)

clauses
    sum([],0).
    sum([X|List],sum):-sum(List,sum1),
    sum=X+sum1.
    

Output:


Post a Comment

0 Comments