pascal的蛇形矩阵,设有一个n*n的矩阵(0<n<50)用pascal语言怎么编?
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/29 19:24:20
pascal的蛇形矩阵,设有一个n*n的矩阵(0<n<50)用pascal语言怎么编?
pascal的蛇形矩阵,设有一个n*n的矩阵(0<n<50)用pascal语言怎么编?
pascal的蛇形矩阵,设有一个n*n的矩阵(0<n<50)用pascal语言怎么编?
program t1;
type arr=array[1..4] of integer;
var a,b:array[0..100,0..100] of integer;
i,j,k,l,m,n:integer;
procedure work;
var i,j,bj,bj1,m,k1,k2,k,j1,j2,j3,j4:integer;
r,p:arr;
begin
k1:=1; k2:=0; k:=0;
for i:=1 to n div 2 do
begin
r[1]:=n-2*(i-1);
r[2]:=r[1]-1;
r[3]:=r[2];
r[4]:=r[2]-1;
for j1:=1 to r[1] do
begin
k:=k+1;
k2:=k2+1;
a[k1,k2]:=k;
end;
for j2:=1 to r[2] do
begin
k:=k+1;
k1:=k1+1;
a[k1,k2]:=k;
end;
for j3:=1 to r[3] do
begin
k:=k+1;
k2:=k2-1;
a[k1,k2]:=k;
end;
for j4:=1 to r[4] do
begin
k:=k+1;
k1:=k1-1;
a[k1,k2]:=k;
end;
end;
if n mod 2=1 then
a[n div 2+1,n div 2+1]:=k+1
end;
begin
assign(input,'sxjz.in');
reset(input);
assign(output,'sxjz.out');
rewrite(output);
readln(n);
work;
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j]:4);
writeln;
end;
end.