Greatest common divisor: Difference between revisions
Content added Content deleted
(added Racket) |
|||
Line 570: | Line 570: | ||
gcd(A,B) when A > B -> gcd(B, A rem B); |
gcd(A,B) when A > B -> gcd(B, A rem B); |
||
gcd(A,B) -> gcd(A, B rem A).</lang> |
gcd(A,B) -> gcd(A, B rem A).</lang> |
||
=={{header|Euler Math Toolbox}}== |
|||
Non-recursive version in Euler Math Toolbox. Note, that there is a built-in command. |
|||
<lang> |
|||
>ggt(123456795,1234567851) |
|||
33 |
|||
>function myggt (n:index, m:index) ... |
|||
$ if n<m then {n,m}={m,n}; endif; |
|||
$ repeat |
|||
$ k=mod(n,m); |
|||
$ if k==0 then return m; endif; |
|||
$ if k==1 then return 1; endif; |
|||
$ {n,m}={m,k}; |
|||
$ end; |
|||
$ endfunction |
|||
>myggt(123456795,1234567851) |
|||
33 |
|||
</lang> |
|||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |