{ Matrix - Summen: Polberechnung          }
{ Autor: Dipl.-Ing. Thomas Speiser        }
{ Source from: http://Codes.TurboTools.de }

program matrix2;
uses Crt;
const n = 25;
var matrix: array[1..n,1..n] of integer;
x,y,sN,sO,sW,sS: integer;

procedure Matrix_fuellen;
begin
randomize;
for x:=1 to n do
for y:=1 to n do begin matrix[x,y]:=random(9);
gotoxy(x,y);write(matrix[x,y]); end;
end;

begin
ClrScr;
Matrix_fuellen;

for x:=1 to n do
for y:=1 to n do begin

if x-y = 0 then begin
Textcolor(red);
gotoxy(x,y); write(matrix[x,y]); end;

if x+y = n+1 then begin
Textcolor(red);
gotoxy(x,y); write(matrix[x,y]); end;

Textcolor(lightgray);
{Summe: NORD Berechung}
if (x-y <> 0) and (x+y <> n+1) and (y < x) and (x+y <= n) then begin
sN:=sN+matrix[x,y];
gotoxy(40,1); write('Summe NORD: ',sN); end;
 {Summe: OST Berechung}
if (x-y <> 0) and (x+y <> n+1) and (y < x) and (x+y > n) then begin
sO:=sO+matrix[x,y];
gotoxy(40,2); write('Summe OST : ',sO); end;

{Summe: WEST Berechung}
if (x-y <> 0) and (x+y <> n+1) and (y > x) and (x+y <= n) then begin
sW:=sW+matrix[x,y];
gotoxy(40,3); write('Summe WEST: ',sW); end;

{Summe: SD Berechung}
if (x-y <> 0) and (x+y <> n+1) and (y > x) and (x+y > n) then begin
sS:=sS+matrix[x,y];
gotoxy(40,4); write('Summe SD : ',sS); end;

end;
readLN;
end.