为矩阵n*n赋值,外层全赋1,第二层全赋2,依此类推
大家帮忙

程序代码:#include <stdio.h>
#define AbsInt(x) ((x)>=0?(x):-(x))
int main()
{
int x, y,size,t,test;
printf("Input the size:");
scanf("%d",&size);
t=size/2;test=(size%2==0?0:size);
for (y = -t; y <= t; y++)
{
if(y==test)
continue;
for (x = -t; x <= t; x++)
{
if(x==test)
continue;
if(AbsInt(y)<=AbsInt(x))
printf("%d ",t-AbsInt(x)+1);
else
printf("%d ",t-AbsInt(y)+1);
}
putchar('\n');
}
return 0;
}代码有受“御坂美琴”大姐姐的一个关于循环的帖子影响,很受教,在此向大姐姐问好~


程序代码:#include <stdio.h>
#define AbsInt(x) ((x)>=0?(x):-(x))
#define size 14
int main()
{
int x, y,t,test;
int array[size][size];
t=size/2;test=(size%2==0?0:size);
int m=0,n=0;//对偶维数的校正
for (y = -t; y <= t; y++)
{
if(y==test)
continue;
for (x = -t; x <= t; x++)
{
if(x==test)
continue;
if(x>test)m=-1;
if(y>test)n=-1;
if(AbsInt(y)<=AbsInt(x))
array[x+t+m][y+t+n]=t-AbsInt(x)+1;
else
array[x+t+m][y+t+n]=t-AbsInt(y)+1;
m=n=0;
}
}
return 0;
}
