Convert integer to array


Question

I would like to convert an integer into an array, so that it looks like the following:

int number = 123456 ;
int array[7] ;

with the result:

array[0] = 1 
array[1] = 2
...
array[6] = 6
1
15
12/19/2012 3:18:57 PM

Perhaps a better solution is to work backwards:

123456 % 10 = 6

123456 / 10 = 12345

12345 % 10 = 5

12345 / 10 = 1234

25
12/7/2009 4:16:50 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon