0

For example: Given number=1234; Failing,how can i separate all the digits from 1st to last?like 1,2,3,4

1 Answers1

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
  • @Michael Yes...1+⌊log10x⌋ is the number of digits.. – Ismail Rubad Nov 04 '13 at 10:32