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

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

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

%  below max function is not predefined you can use any name as function

max(X,Y):-
 X=Y ->
 write('Both are Equal');
  X>Y ->
  ( Z is X,
  write(Z)
  );
  X<Y ->
  ( Z is Y,
  write(Z)
  )).

% Output



No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...