Greatest Common Divisor

This algorithm find the greatest common divisor of two integers.



									function GCD($a, $b)
{
	if ($a == 0)
		return $b;

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

	return $a;
}
								


Example

									$gcd = GCD(15, 12);
								


Output

									3