Programming-Idioms

History of Idiom 74 > diff from v32 to v33

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

Version 32

2019-09-30, 12:13:30

Version 33

2019-10-04, 22:38:35

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)
{
  while (b != 0)
  {
    int t = b;
    b = a % t;
    a = t;
  }
  return a;
}