Sunday, 13 May 2012

Write a prolog program to print sum of all elements of a list.


domains
list=Y*
Y=integer.
predicates
sum(list, Y)
clauses
sum([Y],Y).
sum([Head|Tail],Y) if sum(Tail,Y1) and Y=Y1+Head.

0 comments

 
© 2011-2012 ProgrammingBlue
Posts RSS Comments RSS
Back to top