Question: 1 The Euclidean Algorithm The G C D of two integers, denoted G C D ( x , y ) , is the largest integer

1 The Euclidean Algorithm
The GCD of two integers, denoted GCD(x,y), is the largest integer that divides both x and y. For example, the GCD of 21 and 9,GCD(21,9), is 3. The GCD is an important concept in mathematics and makes regular appearances in the areas of number theory and abstract algebra.
The ancient mathematician Euclid formulated a relatively simple algorithm for computing the GCD of two integers x and y(assume x>y). The algorithm for computing GCD(x,y) proceeds as follows
Calculate the remainder of the division xy. Denote the value by r.
If r=0 then GCD(x,y)=y. Otherwise, set y=x and x=r then return to the previous step.
For this example, you will implement a Euclidean Algorithm that takes two integers as inputs and computes their GCD.
Create a class called EuclideanAlgorithm that contains a main method.
In the EuclideanAlgorithm class, create a public method called GCD that takes two int parameters called x and y as inputs and returns an int.
In the GCD method, declare an int variable called remainder that stores the remainder of xy(Hint: Use the modulus operator).
Use a while loop to implement the repeated portion of Euclid's Algorithm.
Once the GCD has been computed, return the value. Test your code a few times in the main method. A few test cases are provided below:
\table[[x,y,GCD
1 The Euclidean Algorithm The G C D of two

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 Programming Questions!