【发布时间】:2012-09-25 23:57:01
【问题描述】:
我知道如何计算数字的位数之和:
(define (sum-of-digits x)
(if (= x 0) 0
(+ (modulo x 10)
(sum-of-digits (/ (- x (modulo x 10))
10)))))`
但我只是不知道计算数字。而且也不知道如何通过线性迭代进度来做到这一点。
谢谢!!
【问题讨论】:
-
注意:这个问题不一定需要递归。另一种方法是采用 x 的 log10。
标签: count numbers scheme digits recursive-datastructures