Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions