打印蛇形数字遇见的问题
打印如下的图形
1 2 6 7
3 5 8
4 9
10
为何输不出这样结果
int main()
{
int count_line,x,y,n=0;//count_line为斜行数,例如1为一行,32为一行
int a[4][4];
int i,j;
for (count_line=1;count_line<=4;count_line++)
{
if (count_line%2!=0)
{
for (x=count_line-1,j=0;x>=0&&j<=count_line-1;x++,y--)
{
a[x][y]=++n;
}
}
else
{
for (x=count_line-1,y=0;x>=0&&y<=count_line-1;x--,y++)
{
n=1+count_line;
a[x][y]=n-y;
}
}
}
for (i=0;i<5;i++)
{
for (j=0;j<5;j++)
printf("%d",a[i][j]);
printf("\n");
}
getchar();
getchar();
return 0;
}