Mid Coding

Greatest Common Divisor (GCD) — Euclidean?

Algorithm

int GCD(int a, int b)

Follow on:

while (b != 0)

int temp = b;

b = a % b;

a = temp;

return a;

Explanation:

Repeatedly replace (a, b) with (b, a mod b) until b is 0; then a is the GCD.

More from C# Programming Tutorial

All questions for this course