Monthly Archives: November 2012

Euclid’s Algorithm

custom-shadow-masks-headerI want to share a very useful algorithm in calculating the the greatest common divisor between two numbers. This algorithm is called Euclid’s¬†Algorithm.

 

'Euclids Algorithm
Funtion GreatestCommonDivisorEuclid(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
    Dim remainder as integer = num1 Mod num2
    If remainder = 0 then Return num2
    Return GreatestCommonDivisorEuclid(num2, Remainder)
End Function