Greatest common divisor in Prolog

Download source

1
2
gcd(A,0,A) :- !.
gcd(A,B,R) :- T is A mod B, gcd(B,T,R).