Question: Write a C++ recursive function that performs conversion from decimal to any number of base n, where n is in the range 2-10 or n

Write a C++ recursive function that performs conversion from decimal to any number of base n, where n is in the range 2-10 or n = 16 (hexadecimal). The algorithm for this conversion is to repeatedly divide the decimal number by n, until it is 0. Each division produces a remainder, which becomes a digit in the converted number. For example, if we want to convert the decimal 14 number to a number of base 3, we would apply the following steps: 14/3 = 4 remainder 2 4/3 = 1 remainder 1 1/3 = 0 remainder 1 Thus, the result is (112)3. The only problem with this algorithm is that the first division generates the low-order digit, the next division generates the second-order digit, and so on, until the last division produces the high order digit. Thus, if we output the digits as they are generated, they will be in reverse order. Thus, you should use recursion to reverse the order of output. Implement a recursive C++ function that performs the conversion from decimal to any number of base n that has the following header definition: string DecToBaseN(int num, int base); Where, num is the passed decimal number and base is the base of the number to be converted to in the range 2-10 or 16. The function returns the converted number as a string of digits. In the case of base 16, the function returns the converted number as a string of digits and letters (A-F which represent the values 10-15, respectively). For any other illegal base n, the function displays the message Invalid Base: n and returns a null string.

Please help ASAP. Solve using c++ language and the code must work on Vocareum.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!