How to find GCD of two numbers. In this tutorial, I am going to discuss multiple approaches to find GCD of two numbers using Recursion.
Given two input integers, we have to write a code to find GCD of two numbers using recursion.
For example:
Input n1 : 36 n2 : 54
Output 18
Explanation :
The divisiors of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36 and the divisiors of 54 are 1, 2, 3, 6, 9, 18, 27, 54.
Common divisors are 1, 2, 3, 6, 9, 12 and 18.
The GCD (Greatest Common Divisior) for 36 and 54 is 18.
For this program, I assume you are familiar with the concept of recursion. If you don’t know about recursion then check my previous post on recursion vs iteration. →