Android Code Snippet Euclid Algorithm - Common Denominator

SubName: gcd
Author: Euclid

Description: Find the biggest common factor of two integers

B4X:
Sub gcd( a As Int, b As Int) As Int
If b > a Then
    Dim t As Int = a
    a = b
    b = t
End If
Dim m As Int
Do While b <> 0
    m = a Mod b
    a = b
    b = m
Loop
Return a
End Sub
Tags: Euclid, Common Denominator
 
Top