PROGRAMMING:C programming experiment 4-2 finding the greatest common divisor by exhaustive method
The greatest common divisor (GCD) of two positive integers is the largest integer that can divide the two integers. Please implement the function to calculate the greatest common divisor of two numbers by exhaustive method.
###Exhaustive method:
Find the smaller number t between a and B, and then subtract 1 from T. the first one that satisfies the condition of common divisor is the greatest common divisor of a and 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
###Exhaustive method:
Find the smaller number t between a and B, and then subtract 1 from T. the first one that satisfies the condition of common divisor is the greatest common divisor of a and 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