program ExerciseThree type matrix array 10 10 of integer matrixP matri

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
program ExerciseThree;
type
matrix = array [1..10, 1..10] of integer;
matrixP = ^matrix;
sums = array [1..10] of integer;
sumsP = ^sums;
function generateMatrix(rows, columns: integer): matrixP;
var
tempMatrix: matrixP;
begin
New(tempMatrix);
for rows := 1 to rows do begin
for columns := 1 to columns do begin
tempMatrix^[rows, columns] := random(8) + 2;
Write(tempMatrix^[rows, columns], ' ');
end;
WriteLn('');
end;
generateMatrix := tempMatrix;
end;
function calculateColumnsSum(m: matrixP; rows, columns: integer): sumsP;
var
tempSums: sumsP;
begin
New(tempSums);
for columns := 1 to columns do begin
for rows := 1 to rows do begin
tempSums^[columns] := tempSums^[columns] + m^[rows, columns];
end;
Write(tempSums^[columns], ' ');
end;
WriteLn('');
Dispose(tempSums);
end;
begin
randomize;
calculateColumnsSum(generateMatrix(3,4),3,4);
end.