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
Get step-by-step solutions from verified subject matter experts
