program spirall;
uses crt;
const Size=7;
k=0; {"яєёЄр ўхщър" ёюфхЁцшЄ чэрўхэшх k}
var mas:array[1..size,1..size]of shortint;
i,j,a:integer;
function freemas(i,j: shortint): boolean;
begin
if (i<1) or (i>size) or (j<1) or (j>size)
then freemas:=false
else freemas:=(mas[i,j]=k);
end;
begin
clrscr;
i:=1;
j:=1;
mas[i,j]:=1;
for a:=2 to sqr(size) do
begin
if (freemas(i-1,j)) and (not freemas(i,j-1)) then begin dec(i); mas[i,j]:=a; end else
if freemas(i,j+1) then begin inc(j); mas[i,j]:=a; end else
if freemas(i+1,j) then begin inc(i); mas[i,j]:=a; end else
if freemas(i,j-1) then begin dec(j); mas[i,j]:=a; end else
readln;
end;
begin
writeln;
for i:=1 to size do begin
for j:=1 to size do write(mas[i,j]:2,'|');
writeln;
end;
end;
readln;
end.
Не забываем теги [ code] и [ /code] для исходников...
Сообщение отредактировано: volvo -