Question: My working code: #include using namespace std; int GCD(int p, int q); void main() { int p, q; cout cin >> p; cout cin >>

My working code:
#include
using namespace std;
int GCD(int p, int q);
void main()
{
int p, q;
cout
cin >> p;
cout
cin >> q;
cout
}
int GCD(int p, int q)
{
if (q != 0) return GCD(q, p%q);
else return p;
}
Therefore I need the answers to b) and c)
Question 2: (a) The greatest common divisor (GCD) of two positive integers is the largest integer that divides both of them (e.g., the GCD of 102 and 68 is 34.) We know that, when p > q, the GCD of p and q is also the GCD of q and p % q. Implement accordingly the recursive function int GCD(int p, int q), making your code as concise as possible while ensuring it works in all cases. (3 marks) (b) State exactly why the following recursive function is incorrect. (1 mark) int G ( int n) return -n G (n); ) (c) State exactly why the following recursive function is incorrect. (2 marks) int H (int n) if (nreturn 0; if(n%21-0) return 1 + H ( 3*n + 1); else return H (n/2 )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
