Challenge: Greatest Common Divisor

Find the greatest common divisor (GCD) of two integers using recursion.

Problem

Try to find the greatest common divisor of two integers using recursion.

Input

Two integers.

Output

A greatest common divisor (integer).

Sample input

GCD(24, 18)

Sample output

GCD is: 6

Coding exercise

Try to solve this yourself first. If you get stuck or need help, you can always press the ā€œShow Solutionā€ button to see how your problem can be solved. Weā€™ll look at the solution in the next lesson.

Good luck!

Get hands-on with 1400+ tech skills courses.