Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(1) Write a recursive function, gcd, that takes as parameters two integers and returns the greatest common divisor of the numbers. Put this function in

(1) Write a recursive function, gcd, that takes as parameters two integers and returns the greatest common divisor of the numbers. Put this function in a class called GCD. Be prepared to deal with the scenario in which the values are put in any order (y greater than x or vice versa). You will call this from main.cpp. The main.cpp must ask the user to enter two values and return the gcd of those two numbers. (2) Also, write a test program. Plan to include 6 test cases. This will have its own main method. Consider edge/border cases, the order of integers x greater than y and vice versa, test for values having a gcd greater than one as well as values in which one is the gcd.

#include  using namespace std; //recursive function int gcd( int, int ); int main() { int x, y; cout << "Enter first interger(X) : "; cin >> x; cout << "Enter second integer(Y) : "; cin >> y; cout << "G.C.D of " << x << " and " << y << " is : " << gcd( x, y ); cout << " \t"; return 0; } int gcd( int x, int y) { if (y==0) return x; return gcd( y, x % y ); } 

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

=+Are you pregnant?

Answered: 1 week ago