Computers and Technology
Computers and Technology, 04.04.2020 02:09, chops85

Recall that the greatest common divisor of two integers a and b, GCD(a, b), not both of which are zero, is the largest positive integer that divides both a and b. The Euclidean algorithm for finding this greatest common divisor of a and b is as follows:
- Divide a by b to obtain the integer quotient q and remainder r so that a = bq + r. Note: if b = 0, then GCD(a, b) = a.
- Now, GCD(a, b) = GCD(b, r) so replace a with b and b with r, and repeat this procedure
Since the remainders are decreasing, eventually a remainder of 0 will result. The last nonzero remainder is GCD(a, b). For example,
1260 = 198 x 6 + 72 GCD(1260,198) = GCD(198,72)
199 = 72 x 2 + 54 GCD(1260,198) = GCD(72,52)
72 = 54 x 1 + 18 GCD(1260,198) = GCD(54,18)
54 = 18 x 3 + 0 GCD(1260,198) = 18

(a) Write a recursive implementation of the Euclidean GCD function:
int gcd(int a, int b);
[Hint: Note that when the remainder is zero, the divisor will be the GCD]
(b) Write a short program to test your GCD function with the following values:

1280,198
197,13
120,60

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 17:40, math31343
Gabe wants to move text from one document to another document. he should copy the text, paste the text, and open the new document highlight the text, select the cut command, move to the new document, make sure the cursor is in the correct location, and select the paste command select the save as command, navigate to the new document, and click save highlight the text, open the new document, and press ctrl and v
Answers: 1
image
Computers and Technology, 23.06.2019 23:00, GreenHerbz206
Computer programming is one type of what career
Answers: 1
image
Computers and Technology, 24.06.2019 23:00, person76
Systolic pressure is a measure of blood pressure when the ventricles relax and fil with blood ture or false
Answers: 1
image
Computers and Technology, 25.06.2019 08:20, Dweath50
E-commerce builds on traditional commerce by adding the flexibility that networks offer and the availability of the internet. - true or false
Answers: 1
Do you know the correct answer?
Recall that the greatest common divisor of two integers a and b, GCD(a, b), not both of which are ze...

Questions in other subjects: