Page 1 sur 1
[Func] PGCD
Posté : ven. 25 mai 2012 19:49
par silvere
Bonjour,
Voici deux fonction, une pour calculer directement le PGCD (Plus grand commun diviseur) et l'autre pour afficher les calcules si nous voulons le faire a la main.
► Afficher le texte
Code : Tout sélectionner
Func PGCD($Nombre1, $Nombre2)
Local $Resultat
If $Nombre1 = $Nombre2 Then Return $Nombre1
$Reste = Mod($Nombre1, $Nombre2)
While Mod($Nombre2, $Reste) <> 0
$Reste = Mod($Nombre2, $Reste)
WEnd
Return $Reste
EndFunc ;==>PGCD
Func AfficherPGCD($Nombre1, $Nombre2)
Local $return
$Reste = Mod($Nombre1, $Nombre2)
$Quotient = Floor($Nombre1 / $Nombre2)
$return = $Nombre1 & " = " & $Nombre2 & " x " & $Quotient & " + " & $Reste
Do
$Nombre1 = $Nombre2
$Nombre2 = $Reste
$Reste = Mod($Nombre1, $Nombre2)
$Quotient = Floor($Nombre1 / $Nombre2)
$return = $return & @CRLF & $Nombre1 & " = " & $Nombre2 & " x " & $Quotient & " + " & $Reste
Until $Reste = 0
Return $return
EndFunc ;==>AfficherPGCD