1041: 蛇行矩阵
#include<stdio.h>
int main()
{
int a[100][100],m,n,i,j=0,sum=0,t;
scanf("%d",&n);
for(m=1;m<=n;m++)
{
sum=sum+m;
}
a[n-1][0]=sum;//从第一行最后一列开始;
t=n-1;
for(i=t;i>=0;)
{
a[i][j]=sum;
j++;//每次斜向下赋值
i--;
sum--;
if(i==0)
{
a[i][j]=sum;
t=t-1;
i=t;
j=0;
sum--;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
printf("%d ",a[j][i]);
}
printf("\n");
}
}