求告诉这程序思路
#include<stdio.h>#define N 20
void matrx1(int a[][N],int m,int n)
{
int d,x=0,y=0;
int right,left,up,down;
for(d=1;d<=m*n;d++)
{
a[x][y]=d;
right=y<n-1&&a[x][y+1]==0;
left=y>0&&a[x][y-1]==0;
down=x<m-1&&a[x+1][y]==0;
up=x>0&&a[x-1][y]==0;
/* if(right||down)
y++;
else
x++;
if(down||left)
x++;
else if(left||up)
y--;
else if(up||right)
x--;*/
if(right)
{
if(up)
x--;
else
y++;
}
else if(left)
{
if(down)
x++;
else
y--;
}
else if(down)
{
if(right)
y++;
else
x++;
}
else if(up)
{
if(left)
y--;
else
x--;
}
}
}
void output(int a[][N],int m, int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%4d",a[i][j]);
printf("\n");
}
}
void main()
{
int a[N][N]={0};
int m,n;
printf("please input num:\n");
scanf("%d%d",&m,&n);
matrx1(a,m,n);
output(a,m,n);
}