CS 2401 Assignment #5

Due Date: Wednesday, July 11.

Objective: The goal of this assignment is to practice recursion.

Background. Billions of people watch the Olympics, and who knows, maybe the extraterrestrials are watching them too. For them, the competitions are exciting, but the numerical results may be difficult to understand: for us, with ten fingers on both hands, it is natural to use a decimal system, but creatures from other planets may use different bases. Let us help them by designing a universal translator that, given a positive integer n and a base B, prints the description of the given number in the given base.


(Note that we always add space between digits, to avoid confusion: e.g., to make sure that 8 11 = 8 * 121 + 11 = 10710 is different from 8 1 1 = 8 * 122 + 1 * 121 + 1 = 1,06510.)

Algorithm. The algorithm for transforming the number into base B is as follows:


Assignment. Write a recursive method that, given the number n and the base B, prints the result of converting n into base B.

Testing. Test your method on examples where it is easy to manually compute the result: B = 10 and B = 2 (binary code).