Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
pl:prolog:pllib:comon_divisor [2019/06/27 15:50] |
pl:prolog:pllib:comon_divisor [2019/06/27 15:50] (aktualna) |
| ====== Comon divisor ====== |
| {{tag>math}} |
| ===== Description ===== |
| Computing the greatest common divisor of two integers. |
| |
| **Source**: The Art of Prolog |
| ===== Download ===== |
| Program source code: {{comon_divisor.pl}} |
| ===== Listing ===== |
| <code prolog> |
| /* |
| 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 |
| </code> |
| ===== Comments ===== |
| |