Use the base number (10 in our case), and the modulus operator, to help:
Code:
2968 % 10 (our base number) equals 8
2968 / 10 equals
296
296 % 10 equals 6
296 / 10 equals
29
See how that can "peel off" the right most digit of the number, step by step?
Code:
a while loop is helpful:
int i=0, count=0
int digits[5]={0}
while(number > 0) {
digits[i++]=number % 10
number /= 10
count++;
}
Now the digits are in the digits[] array. To see them right, print it out from i=count to 0, instead of the normal way. (that is, counting downward from digits[count] to digits[0], in a for loop.