#include
int main()
{
int i,j,k,n,a[100][100],b[2],t,x,y;
n=5;
b[0]=0;
b[1]=1;
k=n;
t=1;
x=1;
while(x<=n*n)
{
for(y=1;y<=2*k-1;y++)
{
b[y/(k+1)]=b[y/(k+1)]+t;
a[b[0]][b[1]]=x;
x=x+1;
}
k=k-1;
t=-t;
}
for(i=1;i<=n;i++)
{
//printf("\n");
for(j=1;j<=n;j++)
printf("%3d",a[i][j]);
printf("\n");
}
getch();
}