Sunday, February 16, 2025

9. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.

 

Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.

% Write a Prolog program to implement maxlist(List,Max) so that Max is the 
% greatest number in the list of numbers List.


/* Max of n-#.s in a list. */
maxlist([H|T],R):-
 length(T,L),
 L>0 ->
 (
  maxlist(T,R1),
  (
   H > R1 -> 
     R is H
    ;
     R is R1
  )
 ) 
 ;
 R is H.
% Output
Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.
Prolog Program to find maximum number in the list of N numbers.

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