I am trying to write a function which takes a number and returns a list of the number's digits. For example:
(list-num 648)
;=> (6 4 8)
I have written some code, but it returns (8 4 6)
, and I can't use reverse
. MY code so far:
(define (list-num n)
(if (not (equal? (quotient n 10) 0))
(cons (modulo n 10) (list-num(quotient n 10)))
(cons (modulo n 10) '())))