Consider this as a rough idea:
#include <stdio.h>
void PrintArrayClockwise(int *array, int rows, int columns)
{
int r = 0;
int rh = rows / 2;
int i;
while (r < rh)
{
for (i=r; i<(columns - r); i++) printf("%d ",array[(r*columns)+i]);
printf("\n");
for (i=r+2; i<=(rows-r); i++) printf("%d ",array[(i*columns)-1-r]);
printf("\n");
for (i=(columns-r-2); i>=r; i--) printf("%d ",array[((rows-r-1)*columns)+i]);
printf("\n");
for (i=rows-r-2; i>r; i--) printf("%d ",array[(i*columns)+r]);
printf("\n");
r++;
}
}
int main()
{
int numbs[16];
int i;
for (i=0; i<16; i++) numbs[i]=i+1;
PrintArrayClockwise(numbs, 4, 4);
return 0;
}
It should work with arrays of different sizes, both square and not. I didn't check it thoroughfully but it should be a good starting point. :)