蛇形矩阵
1 #include <stdio.h>
2 int main()
3 {
4 int i,j,n,k=0,sum,sn=1,sn1,m;
5 while(scanf("%d",&n)!=EOF)
6 { for(i=1;i<=n;i++)
7 {
8 {
9 printf("%d",sn);
10 sn1=sn;
11 for(j=k+2,m=1;m<=n-i;m++,j++)
12 {
13 sum=sn1+j;
14 printf(" %d",sum);
15 sn1=sum;
16 }
17 printf("\n");
18 sn+=i;
19 k++;
20 }
21 }
22 }
23 return 0;
24 }