ewggwegw ewggwegw - 12 days ago 5
C++ Question

howto split a int into its digits?

how can i split a int in c++ to its single numbers, e.g.:
23 to 2 and 3 ??

Answer

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.

Comments