//****** Program to make GCD by using recursion ********
#include<iostream>
using namespace std;
int GCD(int n1, int n2)
if(n1==0) //if n1==0 then gcd is n2
return n2;
if(n2==0) //if n2==0 then n1 is gcd
return n1;
if(n1==n2) //if both n1 and n2 becomes equal the any one is gcd
return n1;
if(n1>n2)
return GCD(n1-n2,n2); //if n1>n2 the call the function again with passing the argument as n1 -n2
and n2 as its is
return GCD(n1,n2-n1); //if n2>n1 then call the function again with passing the argument as n2-n1 and
n1 as it is
int main()
{
int a, b; //taking the numbers for gcd from user
cout<<"Enter First Number: ";
cin>>a;
cout<<"Enter Second Number: ";
cin>>b;
cout<<"GCD of Numbers is: ";
cout<<GCD(a,b)<<endl; //the recursive function is called first from here and the the ans returns here
return 0;
OUTPUT:-