Question: Problem 2 : Implement a Recursive Conversion Function ( 1 5 points ) Write a program which defines a recursive function that takes a decimal

Problem 2: Implement a Recursive Conversion Function (15 points)
Write a program which defines a recursive function that takes a decimal integer as a parameter and outputs the binary equivalent as a string. The function should output the binary value of the integer one digit at a time. If the integer is even, capture a zero and call the function with the value divided by two; if the integer is odd, capture a one, and do the same. When the function returns to the caller, reverse the captured values to obtain the correct binary representation.
For example, if the input were 42 decimal, the final result would be 101010 binary. Leading zeros should be suppressed.

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 Programming Questions!