Программа
USES CRT;
CONST N=18;
TYPE Matrix=array[1..N,1..N] of integer;
VAR A:Matrix;
Height,Width:1..N;
FUNCTION Min(A,B:integer):integer;
Begin
if A<B then Min:=A
else Min:=B
End;
PROCEDURE OutputMatrix(Height,Width:integer; A:Matrix);
Var i,j:integer;
Begin
Write('┌');
for j:=1 to Width do Write(' ');
WriteLn('┐');
for i:=1 to Height do
begin
Write('│');
for j:=1 to Width do Write(A[i,j]:3,' ');
WriteLn('│')
end;
Write('└');
for j:=1 to Width do Write(' ');
WriteLn('┘');
End;
FUNCTION GetFill(var Fill:integer):integer;
Begin
GetFill:=Fill;
Fill:=Fill+1
End;
PROCEDURE MatrixInput(Height,Width:integer; var A:Matrix);
Var i,k,Fill:integer;
NumberSpiral:integer;
Begin
NumberSpiral:=Min(Height,Width);
NumberSpiral:= NumberSpiral div 2 + Ord(Odd(NumberSpiral));
Fill:=1; { Начальное определение заполнителя }
for k:=1 to NumberSpiral do
begin
for i:=k to Width-k+1 do A[k,i]:=GetFill(Fill);
for i:=k+1 to Height-k+1 do A[i,Width-k+1]:=GetFill(Fill);
if not Odd(Min(Height,Width)) or (k<NumberSpiral) then
for i:=Width-k downto k do A[Height-k+1,i]:=GetFill(Fill);
if not Odd(Min(Height,Width)) or (k<NumberSpiral) then
for i:=Height-k downto k+1 do A[i,k]:=GetFill(Fill)
end
End;
BEGIN
WriteLn; { Пропуск строки }
Randomize;
Height:=Random(N)+1;
Width:=Random(N)+1;
MatrixInput(Height,Width,A);
OutputMatrix(Height,Width,A);
END.
Бесплатные примеры программ
Примеры написанных программ
Помощь студентам по программированию