How can I create a function ggt[p,q],and find the greatest common divisor with Euclid's algorithm?p,q are integer.
1 Answer
$\begingroup$
$\endgroup$
2
Like this:
ggt[p_, q_] := First[NestWhile[{Last[#], Mod @@ #} &, {p, q}, Last[#] != 0 &]]
-
-
$\begingroup$ @JoneWill The function works correctly for rational input too $\endgroup$ Feb 20, 2017 at 7:25