Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
GCD (Euclid’s algorithm)
Core exercise
Write pgcd(int a, int b) that returns the greatest common divisor, using Euclid’s algorithm.
A workshop goes here: you write and run code in it. It requires JavaScript.
Starting code
Exercices.java
public class Exercices {
public static void main(String[] args) {
System.out.println("pgcd(1071, 462) = " + pgcd(1071, 462));
}
public static int pgcd(int a, int b) {
// TODO : algorithme d'Euclide
return 0;
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
As long as b is not zero: the new pair becomes (b, a % b). When b reaches 0, the answer is a.