Question: Implement the following algorithm as the find_gcd function using the outline of the function given below: /* * Finds greatest common divisor of two integers

Implement the following algorithm as the find_gcd function using the outline of the function given below: /* * Finds greatest common divisor of two integers */ Int find_gcd (int n1, int n2) /* input - two integers */ { int gcd; /* Displays trace message */ printf(" Entering find_gcd with n1 = %d, n2 = %d ", n1, n2); /* Asks user for gcd */ printf("gcd of %d and %d?> ", n1, n2); scanf("%d", &gcd); /* Displays exit trace message */ printf("find_gcd returning %d ", gcd); return (gcd); } Your function will find the greatest common divisor (that is, the product of all common factors) of integers n1 and n2 . 1. Put the absolute value of n1 in q and of n2 in p . 2. Store the remainder of q divided by p in r . 3. while r is not zero 4. Copy p into q and r into p . 5. Store the remainder of q divided by p in r . 6. p is the gcd .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!