We can determine how many digits a positive integer has by repeatedly dividing by 10 (without keeping
Fantastic news! We've Found the answer you've been seeking!
Question:
We can determine how many digits a positive integer has by repeatedly dividing by 10 (without keeping the remainder) until the number is less than 10, consisting of only 1 digit. We add 1 to this value for each time we divide by 10. Here is the recursive algorithm:
1. If n < 10 return 1.|
2. Otherwise, return 1 + the number of digits in n/10 (ignoring the fractional part).
Implement this recursive algorithm in Python and test it using a main function that calls this with the values 15, 105, and 15105. Remember that if n is an integer, n/10 will be an integer without the fractional part.
Related Book For
Discrete and Combinatorial Mathematics An Applied Introduction
ISBN: 978-0201726343
5th edition
Authors: Ralph P. Grimaldi
Posted Date: