Comon divisor

Description

Computing the greatest common divisor of two integers.

Source: The Art of Prolog

Download

Program source code: comon_divisor.pl

Listing

/*
   greatest_common_divisor(X,Y,Z) :- 
	Z is the greatest common divisor of the integers X and Y.
*/
     greatest_common_divisor(I,0,I).
     greatest_common_divisor(I,J,Gcd) :-
          J > 0, R is I mod J, greatest_common_divisor(J,R,Gcd).
 
%  Program 8.1    Computing the greatest common divisor of two integers

Comments

pl/prolog/pllib/comon_divisor.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0