Find HCF - Artificial Intelligence Lab file


AIM: Find HCF

domains
P=integer

predicates
hcf(P,P,P).

clauses
    hcf(A,B,HCF):- A=B,HCF=A.
   
    hcf(A,B,HCF):- A<B,NB=B-A,hcf(A,NB,HCF).

    hcf(A,B,HCF):- A>B,NA=A-B,hcf(NA,B,HCF).

Output:


No comments:

Post a Comment