Monday, July 17, 2023

16. Write a Prolog program to implement GCD of two numbers.

 16. Write a Prolog program to implement GCD of two numbers. 


gcd(X,0,X).

gcd(X,Y,Z):-

 R is mod(X,Y),

gcd(Y,R,Z).

OUTPUT:

gcd(6,9,X).

X = 3


No comments:

Post a Comment