Question: Please do question 1 and 2 separately and in one cpp file. Question from Data Structure and algorithm analysis in c++ 1)Write a recursive function

Please do question 1 and 2 separately and in one cpp file. Question from Data Structure and algorithm analysis in c++ 1)Write a recursive function count_ones(int N) that returns the number of 1 in the binary representation of N. Note: use the algorithm of converting from decimal number to binary one. Test cases: a. count_ones(9) 2 b. count_ones(4) 1 c. count_ones(15) 4 2)Write a recursive method power(base, exponent) that, when called, returns base^exponent For example, power(3,4) = 3 * 3 * 3 * 3. Assume that exponent is an integer greater than equal to 1. Hint: The recursion step should use the relationship base^exponent=basebase^(exponent-1) and the terminating condition occurs when exponent is equal to 1, because base^1=base.

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!