Confidential Teaching Materials
Homework 3 Criteria, Page 4 of 10
[p5] 15 points
The greatest common denominator (GCD) of two numbers is the largest integer that divides both
numbers evenly. For example, the GCD of 15 and 5 (written as gcd (15, 5)) is 5 because 5 is the
largest number that divides both 15 and 5. Some more examples:
gcd (24, 12) = 12
gcd (13, 2) = 1
gcd (110, 85) = 5
Finding the GCD of two small numbers can often be done by inspection, but large numbers are a
bit more difficult to deal with. One way of finding the GCD of any two numbers is called the
Euclidian method. With the Euclidian method, you set up three columns, labeled X, Y, and
Remainder. In “X”, the first number is placed; in “Y”, the second number. The remainder that
occurs when X is divided by Y is placed in the “Remainder” column. If the remainder is 0, then
whatever is in column Y is the greatest common denominator. If the remainder is not 0, a new row
in the table is created. The previous row’s Y value is placed in the X column, and the previous
row’s remainder goes in the Y column. The remainder is then computed again, and is placed in the
“Remainder” column. This process repeats until 0 is the remainder.
Consider this example of computing the GCD of 110 and 85
X Y Remainder
110 85 25
85 25 10
25 10 5
10 5 0
This process is rather tedious, and can be greatly aided by a computer. Your job is to write a
recursive module that is passed two numbers as parameters and returns their greatest common
denominator.
[c5] 1 points
Sample Solution: