Question: Write a recursive method for computing a string with the binary digits of a number. If n is even, then the last digit is 0.

Write a recursive method for computing a string with the binary digits of a number. If n is even, then the last digit is 0. If n is odd, then the last digit is 1. Recursively obtain the remaining digits. 

Examples:

* count_zeros(0) returns 1. (binary representation is 0)

* count_zeros(1) returns 0. (binary representation is 1)

* count_zeros(2) returns 1. (binary representation is 10)

* count_zeros(3) returns 0. (binary representation is 11)

* count_zeros(4) returns 2. (binary representation is 100)

* count_zeros(5) returns 1. (binary representation is 101)

* count_zeros(6) returns 1. (binary representation is 110)

* count_zeros(15) returns 0. (binary representation is 1111)

* count_zeros(16) returns 4. (binary representation is 10000)

**You must use the following recursive strategy to implement your program**:

* Check for the cases when n is smallest, and solve them directly.

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!