Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

Does it exceed two pages in length?

Answered: 1 week ago

Question

Does it avoid typos and grammatical errors?

Answered: 1 week ago