number of digits
num-digits
: whole-number -> number
Returns how many digits in the number.
number of digits
- Use conditional.
- Base: answer of 1
number of digits
(define (num-digits n)
(cond [(< n 10) 1]
[else ... ]))
number of digits
- Use conditional.
- Base: answer of 1
- Else: one more than …
number of digits
Trick:
(quotient number 10)
has one fewer digit