free pascal 蛇形方阵怎么打
发布网友
发布时间:2024-10-14 02:09
我来回答
共4个回答
热心网友
时间:2024-10-14 07:52
program sxfz;
var
a:array[1..20,1..20] of integer;
c,t,k,r,n:integer;
begin
writeln('n=');
read(n);
t:=1;k:=1;
for r:=1 to n do
for c:=1 to n do
a[r,c]:=0;
r:=1;c:=1;t:=2;a[1,1]:=1;
while (t<=n*n) do
case k of
1: begin
r:=r+1;
a[r,c]:=t;
t:=t+1;
if c=1 then k:=3;
if c=n then k:=4;
end;
2: begin
c:=c+1;
a[r,c]:=t;
t:=t+1;
if r=1 then k:=4;
if r=n then k:=3;
end;
3: begin
r:=r-1;
c:=c+1;
a[r,c]:=t;
t:=t+1;
if (r=1) then k:=2;
if (c=n) then k:=1;
end;
4: begin
r:=r+1;
c:=c-1;
a[r,c]:=t;
t:=t+1;
if (r=n) then k:=2;
if (c=1)and(r<>n) then k:=1;
end;
end;
for r:=1 to n do
begin
for c:=1 to n do
write(a[r,c]:4);
writeln;
end;
readln;
readln
end.
热心网友
时间:2024-10-14 07:48
program t6;
var i,j,d,n,m:longint;
a:array [1..1000,1..1000] of longint;
begin
readln(n);
i:=1; j:=1; d:=1; m:=1;
repeat
a[i,j]:=m;
case d of
1:begin i:=i+1; if j=1 then d:=2
else if j=n then d:=4 end;
2:begin i:=i-1; j:=j+1; if j=n then d:=1
else if i=1 then d:=3 end;
3:begin j:=j+1; if i=1 then d:=4
else if i=n then d:=2 end;
4:begin i:=i+1; j:=j-1; if i=n then d:=3
else if j=1 then d:=1 end;
end;
m:=m+1;
until m>n*n;
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j]:6);
writeln;
writeln;
end;
readln;
end.
热心网友
时间:2024-10-14 07:48
program snack;
var
a:array[1..20,1..20] of integer;
c,t,k,r,n:integer;
begin
writeln('n=');
read(n);
t:=1;k:=1;
for r:=1 to n do
for c:=1 to n do
a[r,c]:=0;
r:=1;c:=1;t:=2;a[1,1]:=1;
while (t<=n*n) do
case k of
1: begin
r:=r+1;
a[r,c]:=t;
t:=t+1;
if c=1 then k:=3;
if c=n then k:=4;
end;
2: begin
c:=c+1;
a[r,c]:=t;
t:=t+1;
if r=1 then k:=4;
if r=n then k:=3;
end;
3: begin
r:=r-1;
c:=c+1;
a[r,c]:=t;
t:=t+1;
if (r=1) then k:=2;
if (c=n) then k:=1;
end;
4: begin
r:=r+1;
c:=c-1;
a[r,c]:=t;
t:=t+1;
if (r=n) then k:=2;
if (c=1)and(r<>n) then k:=1;
end;
end;
for r:=1 to n do
begin
for c:=1 to n do
write(a[r,c]:4);
writeln;
end;
readln;
readln
end.
就是这样
热心网友
时间:2024-10-14 07:53
program lk006;
var
a:array[1..20,1..20] of integer;
c,t,k,r,n:integer;
begin
writeln('n=');
read(n);
t:=1;k:=1;
for r:=1 to n do
for c:=1 to n do
a[r,c]:=0;
r:=1;c:=1;t:=2;a[1,1]:=1;
while (t<=n*n) do
case k of
1: begin
r:=r+1;
a[r,c]:=t;
t:=t+1;
if c=1 then k:=3;
if c=n then k:=4;
end;
2: begin
c:=c+1;
a[r,c]:=t;
t:=t+1;
if r=1 then k:=4;
if r=n then k:=3;
end;
3: begin
r:=r-1;
c:=c+1;
a[r,c]:=t;
t:=t+1;
if (r=1) then k:=2;
if (c=n) then k:=1;
end;
4: begin
r:=r+1;
c:=c-1;
a[r,c]:=t;
t:=t+1;
if (r=n) then k:=2;
if (c=1)and(r<>n) then k:=1;
end;
end;
for r:=1 to n do
begin
for c:=1 to n do
write(a[r,c]:4);
writeln;
end;
readln;
readln
end.