Skip to main content

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.

Back to lesson: Practice: Method toolkit