gcd(X,Y):-X=Y,write('GCD of two numbers is '),write(X);
X=0,write('GCD of two numbers is '),write(Y);
Y=0,write('GCD of two numbers is '),write(X);
Y>X,Y1 is Y-X,gcd(X,Y1);
X>Y,Y1 is X-Y,gcd(Y1,Y).
Output
1 ?- gcd(3,3).
GCD of two numbers is 3
true .
2 ?- gcd(3,9).
GCD of two numbers is 3
true .
3 ?- gcd(3,0).
GCD of two numbers is 3
true .
4 ?- gcd(0,9).
GCD of two numbers is 9
true .
5 ?- gcd(34,56).
GCD of two numbers is 2
true
0 comments:
Post a Comment