Sunday, February 16, 2025

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

 

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

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

max2([H],H).
max2([H|T],R):-
 max2(T,M1),
 H>=M1,
 R is H,!.
max2([H|T],R):-
 max2(T,M1),
 H<M1, 
 R is M1.
% Output
Prolog program to implement maxlist(List,Max)
Prolog program to implement maxlist(List,Max) using cut predicate.

1 comment:

  1. Struggling with coding concepts, debugging, algorithms, or project requirements? Understanding programming takes practice, logical thinking, and clear guidance. Students can benefit from assistance with code structure, problem-solving techniques, and programming fundamentals. Professional help with programming assignment can provide useful guidance, explanations, and practical support while helping learners strengthen their technical skills. Choose a reliable academic support provider that focuses on clear communication, original guidance, timely assistance, and helping students develop confidence in completing programming coursework.

    ReplyDelete

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