Lab 15.1 Greatest Common Divisor A formula for finding the greatest common divisor (GCD) of two numbers was formulated by the mathematician Euclid around 300 BCE. The GCD of two numbers is the largest...


Lab 15.1 Greatest Common Divisor<br>A formula for finding the greatest common divisor (GCD) of two numbers was formulated by the<br>mathematician Euclid around 300 BCE. The GCD of two numbers is the largest number that will divide<br>into both numbers without any remainder. For example, the GCD of 12 and 16 is 4, the GCD of 18 and<br>12 is 6.<br>The basic algorithm is as follows:<br>Assume we are computing the GCD of two integers x and y. Follow the steps below:<br>1. Replace the larger of x and y with the remainder after (integer) dividing the larger number by the<br>smaller one.<br>2. If x or y is zero, stop. The answer is the nonzero value.<br>3 If neither x nor y is zero, go back to step 1.<br>Here is an example listing the successive values of x and y:<br>$ (135 / 20) - 15<br>$ (20 / 15) = 5<br>* (15 / 5) = 0<br>135<br>20<br>15<br>20<br>15<br>5<br>5<br>GCD = 5<br>Write a recursive method that finds the GCD of two numbers using Euclid's algorithm.<br>public class Arithmetic<br>{<br>public static int gcd(int a, int b)<br>// Your work here<br>Lab 15.2 Tester for GCD<br>Write a tester program for your GCD algorithm.<br>

Extracted text: Lab 15.1 Greatest Common Divisor A formula for finding the greatest common divisor (GCD) of two numbers was formulated by the mathematician Euclid around 300 BCE. The GCD of two numbers is the largest number that will divide into both numbers without any remainder. For example, the GCD of 12 and 16 is 4, the GCD of 18 and 12 is 6. The basic algorithm is as follows: Assume we are computing the GCD of two integers x and y. Follow the steps below: 1. Replace the larger of x and y with the remainder after (integer) dividing the larger number by the smaller one. 2. If x or y is zero, stop. The answer is the nonzero value. 3 If neither x nor y is zero, go back to step 1. Here is an example listing the successive values of x and y: $ (135 / 20) - 15 $ (20 / 15) = 5 * (15 / 5) = 0 135 20 15 20 15 5 5 GCD = 5 Write a recursive method that finds the GCD of two numbers using Euclid's algorithm. public class Arithmetic { public static int gcd(int a, int b) // Your work here Lab 15.2 Tester for GCD Write a tester program for your GCD algorithm.

Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here