Its not clear what your sequence is .. but if you look at this
{ for ( int k = 0; k < size; k++) { X[count] = k;
Z[count] = i;
Y[count] = j;}
vs what you have written, should it not be
...
{ for ( int k = 0; k < size; k++) { X[count] = i;
Y[count] = j;
Z[count] = k;}
you also need to learn how to use debugger and to step through your program, which by then observing the values of the variables etc would show you what is/isnt happening