turning the digits of a number into an array int main()
{
    int x,numDigits,i,y,a,diff;
    scanf("%d",&amp;x);

    a=x;
    int result = 1;
    int base=10;
    numDigits=0;

    do
    {
        ++numDigits;
        x = x / 10;
    } while ( x&gt;0 );


    for(result=1;numDigits&gt;0;--numDigits){
        result *= base;
        i=result;

        y=a%i;
        while(y&gt;10){
            y=y/10;
        }
        printf(" %d",y);
    }
    return 0;
}


I manage to seperate integer's digits one by one. But I was not able to collect them in an array. Even though with limited numbers without taking input from user it is easier, I also want to process these numbers but I got stuck.
You can use the standard C function sprintf(buffer,"%d",x) to get an array of digits. In this case, the buffer will contain big-endian representation of x, so the conversion to a digit from each char will be something like this

for(int i = 0; buffer[i] != '\0' &amp;&amp; i &lt; sizeof(buffer);++i)
  digits[i] = buffer[i] - '0';


This work if x is positive.

But if you want to make your own implementation of splitting a number into digits, you should analyze the problem:


What is the base - is it always 10?
How many digits could be - is it always int, i.e. mostly 32-bit?


The answer for first question is to have the base parameter int base = 10 or 2 or 3 or 8 or any you want.

The answer for second question is ceil( log(|x| + 1) / log(base) ) + 1. The +1 for the minus sign. Or if you didn't want to care about maximum of digits use char digits[128] - more than enough even for 64-bit integer.

So, how to fill digits?

// int x - somewhere
unsigned base = 10;

char digits[128];
char isNegative = 0;
int digit = 0;

unsigned tmp = x; // this fix INT_MIN problem thanks chux - Reinstate Monica for note
if(x &lt; 0) {
  isNegative = 1;
  tmp = -x;
} 
if(x == 0) {
  digits[0] = 0;
  digit = 1;
} else {
  for(digit = 0; tmp &gt; 0; ++digit) {
    digits[digit] = tmp % base;
    tmp /= base;
  }  
}


At least you got little-endian representation of x on base as digits[i], where 0 &lt;= i &lt; digit and isNegative for the minus sign