#include <stdio.h>
#include <stdlib.h>
#define N 5
int cube[N][N];
int left = 0;
int right = N-1;
int top = 0;
int botton = N-1;
int num = 1;
void trend(int tr);
int main()
{
int k;
int i, j;
for(k=1;k<(2*N);k++)
{
trend(k);
}
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
printf("%3d ",cube[i][j]);
}
printf("\n");
}
}
void trend(int tr)
{
int i;
int j;
switch(tr%4)
{
case 1:
j = left;
if(tr==1)
{
for(i = 0;i<=botton;i++)
{
cube[i][j] = num;
num++;
}
}
else
{
for(i = top+1;i<=botton;i++)
{
cube[i][j] = num;
num++;
}
top++;
}
break;
//i+,j
case 2:
i = botton;
for(j = left+1;j<=right;j++)
{
cube[i][j] = num;
num++;
}
left++;
break;
//j+,i
case 3:
j = right;
for(i = botton-1;i>=top;i--)
{
cube[i][j] = num;
num++;
}
botton--;
break;
//i-,j
case 0:
i = top;
for(j = right-1;j>=left;j--)
{
cube[i][j] = num;
num++;
}
right--;
break;
//j-,i
}
}