Plus grand denominateur commun

Contenu du snippet

Recherche le plus grand denomiateur commun entre 2 chiffres.

Source / Exemple :


'***********************************************************************************************************
' Name       : xGCF
' Purpose    : Returns the Greatest Common Factor
'              i.e. The largest number which will evenly divide into both X and Y
' Syntax     : xGCF(Number1, Number2)
' Parameters : Number1  : 1st number
'              Number2  : 2nd number
' Return     : The Greatest Common Factor
'***********************************************************************************************************
Public Function xGCF(ByVal Number1 As Long, ByVal Number2 As Long) As Long
    Dim lngTemp As Long
    
    Number1 = Abs(Number1) 'Make both numbers positive
    Number2 = Abs(Number2)
    lngTemp = Number1 Mod Number2
    
    Do While lngTemp > 0
        Number1 = Number2
        Number2 = lngTemp
        lngTemp = Number1 Mod Number2
    Loop
    
    xGCF = Number2
End Function

A voir également