2. Write a recursive function GCD that returns the greatest common divisor of two integers. Where GCD is the largest integer that evenly divides each of the numbers.
Sample output
Enter two numbers: 21 14
GCD is: 7
#include <iostream>
usingnamespace std;
int GCD(int a, int b)
{
if(b == 0)
{
return a;
}
else
{
return GCD(b, a % b);
}
}
int main()
{
int a,b;
cout << "enter two numbers: ";
cin >> a>>b;
cout << "GCD is: " << GCD(a,b) << endl;
return 0;
}
/*
enter two numbers: 21 14
GCD is: 7
Press any key to continue
*/