Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The greatest common divisor (gcd) of two integers a and b is a positive integer

ID: 3622350 • Letter: T

Question

The greatest common divisor (gcd) of two integers a and b is a positive integer c such that c divides a, c divides b, and for any other common divisor d of a and b, d is less than or equal to c. (For example, the gcd of 18 and 45 is 9.) One method of finding the gcd of two positive integers (a, b) is to begin with the smaller (a) and see if it is a divisor of the larger (b). If it is, then the smaller is the gcd. If not, find the next largest divisor of a and see if it is a divisor of b. Continue this process until you find a divisor for both a and b. This is the gcd of a and b.

Write an interactive C++ program that will accept two positive integers as input and then print out their gcd. Enhance your output by printing all divisors of a that do not divide b.

Also, allow the user to repeat the program or quit if they choose. For example, you could then show:
Would you like to repeat this program? Enter “Y” for Yes or “N” for No.

Explanation / Answer

please rate.. #include using namespace std; int gcd(int m, int n) // function definition { // block begin int r; // declaration of remainder while (n != 0) { // not equal r = m % n; // modulus operator m = n; // assignment n = r; } // end while loop return m; // exit gcd with value m } int main() { int x, y; char c='y'; cout x >> y; cout