
952 CHAPTER 13 Recursion
Figure 13.5
A Run of Example 13.2 if
the Base Case Is Not
Coded
Figure 13.5 shows a run of Example 13.2 (the RecursiveFactorial class) with
lines 20 to 22 commented out.
13.2.2 Computing the Greatest Common Divisor
A common algebra problem is to calculate the greatest common divisor, or
gcd, of two positive integers. The gcd is the greatest positive integer that
divides evenly into both numbers.
For example, consider 50 and 20. We can figure in our head that 5 divides
evenly into both numbers, but so does 10. Since we can’t find a number greater
than 10 that divides evenly into both numbers, 10 is the gcd of 50 and 20.
It is easy ...