Monday, 31 October 2016

Write a Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.

% Write a Prolog program to implement max(X,Y,Max) so that Max is the greater of
% two numbers X and Y.

/* Max of two #.s */

/* without list. */
max(X,Y,R):-
 X>=Y -> 
  R is X, 
  write(R)
 ;
  R is Y,
  write(R).


/* with list. */
grandiose([H|T],R):-
 H>T -> 
  R is H,
  write(R)
  ;
  R is T,
  write(T).

% Output
 Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.
 Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.

No comments:

Post a Comment