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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s