How do I split an int into its digits?

前端 未结 15 1569
渐次进展
渐次进展 2020-11-27 17:51

How can I split an int in c++ to its single numbers? For example, I\'d like to split 23 to 2 and 3.

15条回答
  •  无人及你
    2020-11-27 18:00

    Given the number 12345 :

    5 is 12345 % 10
    4 is 12345 / 10 % 10
    3 is 12345 / 100 % 10
    2 is 12345 / 1000 % 10
    1 is 12345 / 10000 % 10

    I won't provide a complete code as this surely looks like homework, but I'm sure you get the pattern.

提交回复
热议问题