Practice · 4 of 5
Euclid's algorithm
CHALLENGE
Difficulty: beginner+25 XP
Implement int gcd(int a, int b): the greatest common divisor. While b != 0, replace (a, b) with (b, a % b); the answer is the final a. This is the classic loop-with-variables trace.
Press Submit to check your solution.
Back to lesson: Practice: Method toolkit