Problem Statement :-

An ant is standing at the left most corner in a room(matrix of order m*n). It has a sack of sugar cubes,,with cubes having numbers written on them. The ant goes on dropping the sugar cubes in ascending order while moving from that corner at the side of the wall in spiral format. As soon as it finishes one round of the room the dropped cubes seem to be a new wall for the ant. The ant again repeats the entire move till the entire room gets filled with a single layer of cubes. Represent it in the form of 2-D matrix.

Fun problem, a little different from most other standard ones.

11*24*23*22*21*20
12*25*26*27*28*19
13*14*15*16*17*18

Like that?

You can iterate through with two variables, i,j so that if i=j, you switch directions. (note: C/C++ arrays are zero-based).