Question: Use recursion to write a function count_ones that returns how many 1s there are in a number n when represented in decimal (base 10). For

Use recursion to write a function count_ones that returns how many 1s there are in a number n when represented in decimal (base 10). For example, 1231 has two 1s. You can assume that n is positive and at most 9 digits long. In the main function perform at least five tests of count_ones and use assert to check that the returned value is correct. Your function must have the following prototype:

int count_ones(int n);

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!