Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
Ask for two positive integers a and b. Use Euclid’s algorithm to find their GCD:
While b is not zero, set (a, b) = (b, a % b). Then a is the GCD.
Print a.
Skills: while, tuple-style reassignment or temp variable.
Example: GCD(48, 18) = 6.