蛇形矩阵
include<stdio.h>
int main()
{int n;
scanf("%d",&n);
int a[n][n],i,j,count=1;
for(i=0;i<n;i++)
{if(i%2==0)
{for(j=0;j<=i;j++)
{a[i-j][j]=count;//(i-j)+j=i=层数;
count++;}}
else
{for(j=0;j<=i;j++)
{a[j][i-j]=count;
count++;}
}}
for(int i=n;i<2*n-1;i++)
{if(i%2==0)
{for(j=n-1;j>=i-(n-1);j--)
{a[j][i-j]=count;
count++;}}
else
{for(j=n-1;j>=i-(n-1);j--)
{a[i-j][j]=count;
count++;}
}}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{printf("%d ",a[i][j]);}
printf("\n");}}