چاپ مارپیچی سری اعداد با آرایه دو بعدی - پاسکال

amir.tak

New member

program pascal;
uses crt;
type a= array [1..100,1..100] of integer;
var x:a; i,n,j,k,s,e,d:integer;
begin
clrscr;
write('enter n in matrix n * n:');
readln(n);
s:=1; e:=1; k:=1; d:=n;
while k<=(n*n) do
begin
for j:=e to d do
begin
x[s,j]:=k; k:=k+1;
end;
e:=e+1;
for i:=e to d do
begin
x[i,d]:=k; k:=k+1;
end;
for j:=d-1 downto s do
begin
x[d,j]:=k; k:=k+1;
end;
for i:=d-1 downto e do
begin
x[i,s]:=k; k:=k+1;
end;
s:=s+1;
d:=d-1;
end;
for i:=1 to n do
begin
for j:=1 to n do
write(x[i,j]:5);
writeln;
writeln;
end;
readln;
end.​

منبع :http://www.daneshju-club.com
 
بالا