PROGRAMMING:C programming experiment 4-4 recursive method to find the greatest common divisor
The greatest common divisor (GCD) of two positive integers is the largest integer that can divide the two integers. Please implement the program, using recursive method to calculate the greatest common divisor of two numbers.
###Recursion method:
When a > b, the greatest common divisor of a and B is equivalent to the greatest common divisor of a - B and B;
When b > A, the greatest common divisor of a and B is equivalent to the greatest common divisor of B - A and a;
When a = B, the greatest common divisor of a and B is a (or b);
###Program input:
Two positive integers are entered by the user
###Program output:
The greatest common divisor of two positive integers.
If the input number is not a positive integer, the program outputs:
```
Input number should be positive!
```
###Function interface definition:
```c++
int Gcd(int a, int b);
```
Where 'a' and 'B' are two positive integers entered by the user.
Function returns the greatest common divisor of 'a' and 'B'.
If 'a' or 'B' is less than or equal to 0, the function returns - 1.
###Main program example:
Here is the main function and an example of calling GCD function
```c++
#include
int Gcd(int a, int b);
int main()
{
int a, b, c;
scanf("%d %d", &a, &b);
c = Gcd(a,b);
if (c != - 1)
{
printf("%d\n", c);
}
else
{
printf("Input number should be positive!\ n");
}
return 0;
}
/*Please complete the GCD function here*/
```
###Input example:
Here is a set of inputs. For example:
```in
15 20
```
###Output example:
The corresponding output is given here. For example:
```out
five
```
answer:If there is no answer, please comment
###Recursion method:
When a > b, the greatest common divisor of a and B is equivalent to the greatest common divisor of a - B and B;
When b > A, the greatest common divisor of a and B is equivalent to the greatest common divisor of B - A and a;
When a = B, the greatest common divisor of a and B is a (or b);
###Program input:
Two positive integers are entered by the user
###Program output:
The greatest common divisor of two positive integers.
If the input number is not a positive integer, the program outputs:
```
Input number should be positive!
```
###Function interface definition:
```c++
int Gcd(int a, int b);
```
Where 'a' and 'B' are two positive integers entered by the user.
Function returns the greatest common divisor of 'a' and 'B'.
If 'a' or 'B' is less than or equal to 0, the function returns - 1.
###Main program example:
Here is the main function and an example of calling GCD function
```c++
#include
int Gcd(int a, int b);
int main()
{
int a, b, c;
scanf("%d %d", &a, &b);
c = Gcd(a,b);
if (c != - 1)
{
printf("%d\n", c);
}
else
{
printf("Input number should be positive!\ n");
}
return 0;
}
/*Please complete the GCD function here*/
```
###Input example:
Here is a set of inputs. For example:
```in
15 20
```
###Output example:
The corresponding output is given here. For example:
```out
five
```
answer:If there is no answer, please comment