Entrez deux nombres pour calculer leur PGCD :
Principe de l\'algorithme :
PGCD(a, b) = PGCD(b, a % b)
Si b = 0 alors PGCD(a, b) = a
Fonction PGCD(a, b)
Début
Tant que b ≠ 0 faire
temp = b
b = a % b
a = temp
Fin Tant que
Retourner a
Fin
Voici comment fonctionne l\'algorithme d\'Euclide pour calculer le PGCD :
Pour calculer PGCD(48, 18) :
1. PGCD(48, 18) : 48 % 18 = 12, donc PGCD(18, 12)
2. PGCD(18, 12) : 18 % 12 = 6, donc PGCD(12, 6)
3. PGCD(12, 6) : 12 % 6 = 0, donc PGCD(6, 0)
4. Comme b = 0, PGCD(6, 0) = 6.
Le PGCD de 48 et 18 est donc 6.