20_09

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.

 Source Code :

 

max([H],H).

max([H|T],R):-

 max(T,M1),

 H>=M1,

 R is H,!.

max([H|T],R):-

 max(T,M1),

 H<M1,

 R is M1.

 

Output :

 

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

No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...