top of page
PROGRAMMING CHALLENGES
Recursive Greatest Common Divisor
Difficulty:
3 Hard
2.5 Recursion
Topic:
The following pseudocode calculates the greatest common divisor (GCD) of two numbers using recursion. Rewrite this algorithm to use iteration instead.
The GCD can be calculated using the Euclidean algorithm. Consider how a while loop can replace the recursive calls to continuously apply the GCD calculation.
FUNCTION gcd(a, b) IF b == 0 RETURN a ELSE RETURN gcd(b, a % b) ENDFUNCTION
Need help with your programming skills?
If you need more help than just independent practise, then we're here for you. Book a 1:1 with us and we will be able to guide you to becoming a proficient programmer who can tackle any of the challenges an exam board can throw at you.
1 hr
50 British pounds1 hr
55 British pounds
bottom of page