Sunday, February 16, 2025

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

 

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

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

/* Sum of the numbers from the list. */

sumlist([],0).
  
sumlist([H|T],R):-
  sumlist(T,R1),
  R is H+R1.
% Output
Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List.
Prolog Program to find the sum of numbers in the list.

No comments:

Post a Comment

15. Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.

  Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list ...