Prolog program to find minimum and maximum

  • Find out the MAXIMUM and MINIMUM values among three numbers:
  • 
    domains
    predicates
    max(integer,integer,integer)
    min(integer,integer,integer)
    maxmin(integer,integer,integer)
    clauses
    max(A,B,C):-
    	A>B,
    	A>C,
    	write(A).
    max(A,B,C):-
    	A>B,
    	write(C).
    max(_,B,C):-
    	B>C,
    	write(B).
    max(_,_,C):-
    	write(C).
    
    min(A,B,C):-
    	A<B,
    	A<C,
    	write(A).
    min(A,B,C):-
    	A<B,
    	write(C).
    min(_,B,C):-
    	B<C,
    	write(B).
    min(_,_,C):-
    	write(C).
    
    maxmin(A,B,C):-
    	max(A,B,C),
    	min(A,B,C).
    

    Leave a Reply

    Please log in using one of these methods to post your comment:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google photo

    You are commenting using your Google account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s