-
Start on this
Can anyone tell me how to get started on this assignment?
The greatest common divisor of two positive intergers is the largest interger that divides the numbers exactly. We can write a recursive formula for finding the GCD, given that the two numbers are called a and b, as:
GCD[a, b] = a, if b = 0
GCD[a, b]= LCF[b, a%b], if b > 0
Implement this recursive formula as a recursive C++ function, and write a driver program that allows you to test it interactively.
-
Start by writing the function prototype. Then add temporary code to return 0 no matter what from the function. Then write the driver program, compiling and testing as you go.
Then start adding code to the function. Perhaps you could start by implementing the stop case for the recursive function. Then add code that does the work. Keep compiling and testing as you go.
Then you are done.
-
Code:
// Returns GCD[arg1, arg2]
int GCD (int arg1, int arg2) {
int result;
// Do the operations here
return result;
}
// Returns LCD[arg1, arg2]
int LCD (int a, int b) {
int result;
// Do the operations here
return result;
}
int main (void) {
// Implement your driver here.
return 0;
}
-
your result is not initialized - your current prototypes return garbage