Greatest Common Divisor

This algorithm find the greatest common divisor of two integers.



									Public Shared Function GCD(a As Integer, b As Integer) As Integer
	If a = 0 Then
		Return b
	End If

	While b <> 0
		If a > b Then
			a -= b
		Else
			b -= a
		End If
	End While

	Return a
End Function
								


Example

									Dim _gcd = GCD(15, 12)
								


Output

									3