Logo

Programming-Idioms

History of Idiom 74 > diff from v33 to v34

Edit summary for version 34 by bigwavedave:
New Csharp implementation by user [bigwavedave]

Version 33

2019-10-04, 22:38:35

Version 34

2019-10-04, 22:40:24

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Code
int gcd(int a, int b)
{
  if (b == 0) 
    return a;
  else 
    return gcd(b, a % b);
}