Euclidean Algorithm


Given two, positive, whole integers m and n, find their greatest common divisor (GCD).

That is, find the largest, positive integer that evenly divides both m and n.

Integer  m:
Integer  n:
do {
   r = m % n;
   if (r == 0) {
       return gcd;
   } else {
       m = n;
       n = r;
   }
} while (r > 0);
                        

GCD