C# How To Find the GCD of Two Numbers
Find GCD
The greatest common divisor (GCD) is the largest number that divides two numbers without a remainder. You can find it with the Euclidean algorithm:
Example
int a = 36;
int b = 60;
while (b != 0)
{
int temp = b;
b = a % b;
a = temp;
}
Console.WriteLine("GCD: " + a);
Explanation:
In each step, b becomes the remainder of a % b, and a becomes the old b.
When the remainder is 0, a holds the GCD. Both 36 and 60 can be divided by 12.