Greatest Common Divisor

This algorithm find the greatest common divisor of two integers.



									public static int GCD(int a, int b)
{
	if (a == 0)
		return b;

	while (b != 0)
	{
		if (a > b)
			a -= b;
		else
			b -= a;
	}

	return a;
}
								


Example

									int gcd = GCD(15, 12);
								


Output

									3