Question: First write a method to calculate the greatest common divisor (GCD) of two positive integers using Euclids algorithm (also known as the Euclidean algorithm). Then
First write a method to calculate the greatest common divisor (GCD) of two positive integers using Euclids algorithm (also known as the Euclidean algorithm). Then write a main method that requests two positive integers from the user, validates the input, calls your method to compute the GCD, and outputs the return value of the method (all user input and output should be done in main). Check Wikipedia to find more information about GCDs1 and Euclids algorithm2. In particular, you will find this pseudocode for calculating the GCD, which should be useful to you: function gcd(a, b) while b 0 t := b b := a mod b a := t return a Here is an example run of the program: Enter a: 34 Enter b: 289 The GCD of 34 and 289 is 17
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
