Computer scientists and mathematicians often use numbering systems other than base 10. Write a program that allows a user to enter a number and a base and then prints out the digits of the number in the new base. Use a recursive function baseConversion (num, base) to print the digits. Hint: Consider base 10. To get the rightmost digit of a base 10 number, simply look at the remainder after dividing by 10. For example, 153 % 10 is 3. To get the remaining digits, you repeat the process on 15, which is just 153 // 10. This same process works for any base. The only problem is that we get the digits in reverse order (right to left). The base case for the recursion occurs when num is less than base and the output is simply num. In the general case, the function (recursively) prints the digits of num // base and then prints num % base. You should put a space between successive outputs, since bases greater than 10 will print out with multi-character "digits." For example, baseConversion(1234, 16) should print 4 13 2.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

Computer scientists and mathematicians often use numbering systems other than base 10. Write a program that allows a user to enter a number and a

base and then prints out the digits of the number in the new base. Use a recursive function baseConversion (num, base) to print the digits.
Hint: Consider base 10. To get the rightmost digit of a base 10 number, simply look at the remainder after dividing by 10. For example, 153 % 10
is 3. To get the remaining digits, you repeat the process on 15, which is just 153 // 10. This same process works for any base. The only problem
is that we get the digits in reverse order (right to left).
The base case for the recursion occurs when num is less than base and the output is simply num. In the general case, the function (recursively)
prints the digits of num // base and then prints num % base. You should put a space between successive outputs, since bases greater than 10 will
print out with multi-character "digits." For example, baseConversion(1234, 16) should print 4 13 2.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr