Традиционнный Pascal:
function Sum(var M:matrix;n:integer;s1,s2:num):real;
var
i,j:number;
s:real;
begin
s:=0;
for i:=1 to n do
if i in s1 then
for j:=1 to n do
if j in s2 then s:=s+M[i,j];
Sum:=s
end;
В PascalABC.Net можно написать короче:
function Sum(var M:matrix;n:integer;s1,s2:num):real;
var
i,j:number;
begin
result:=0;
foreach i in s1 do
foreach j in s2 do result:=result+M[i,j]
end;