For example: Given number=1234; Failing,how can i separate all the digits from 1st to last?like 1,2,3,4
Asked
Active
Viewed 82 times
0
-
You can write it in base 10 :) – BlackAdder Nov 04 '13 at 09:52
-
@yanbo To me it seems like, given $N$ the OP asks for a way to get the sequence $a_i$ of the decimal digits of $N$ in order of magnitude. – AlexR Nov 04 '13 at 09:53
1 Answers
3
Hint
$\lfloor \log_{10} x \rfloor$ is the number of digits (starting with $0$) and
$\left\lfloor \frac{x}{10^i} \right\rfloor {\rm mod}\ 10$ is the $i$-th digit (the digit with magnitude $10^i$).
Digits of naturals are counted from $0$ to $n-1$ where $n$ is the length of the string representation.
AlexR
- 24,905
-
That should be $1+\lfloor\log_{10}x\rfloor$ digits, or $i$ counts down from $\lfloor\log_{10}x\rfloor$ to 0. – Empy2 Nov 04 '13 at 10:05
-
@Michael my notation is consistent with the $i$-th digit ;-). The $0$-th digit is the one with magnitude one. I elaborated on that a little bit. – AlexR Nov 04 '13 at 10:08
-