Question: C++ Recursive Algorithms Writing a program For some data analysis you are working on, you need to find the factorial of some numbers, then convert

C++ Recursive Algorithms Writing a program

For some data analysis you are working on, you need to find the factorial of some numbers, then convert them from decimal to binary.

You setup the following examples to find the factorial of the number 4 and 10 using recursion:

* 4! = 4 * 3 * 2 * 1

* 10! = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1

This help you develop the recursive algorithm for the factorial() function. What is the recursive case? What is the base case? What parameters would be passed to the function?

You also setup the following examples to convert the decimal numbers ((25)10 and (24)10) to their binary representation ((11001)2 and (11000)2 ) using recursion:

* 25 / 2 = 12 and 25 % 2 = 1

* 12 / 2 = 6 and 12 % 2 = 0

* 6 / 2 = 3and 6 % 2 = 0

* 3 / 2 = 1and 3 % 2 = 1

* 1 / 2 = 1and 1 % 2 = 1

* 24 / 2 = 12 and 24 % 2 = 0

* 12 / 2 = 6 and 12 % 2 = 0

* 6 / 2 = 3and 6 % 2 = 0

* 3 / 2 = 1and 3 % 2 = 1

* 1 / 2 = 1and 1 % 2 = 1

This help you develop the recursive algorithm for the decToBin() function. What is the recursive case? What is the base case? What parameters would be passed to the function? Do you think you need a function to reverse the binary string?

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!