program MainDiagonalSum;varmatrix: array[1..3, 1..3] of integer;i, j, sum: integer;beginsum := 0;
writeln('Enter elements of the matrix:');for i := 1 to 3 dofor j := 1 to 3 dobeginwrite('matrix[', i, '][', j, ']: ');readln(matrix[i, j]);end;
writeln('Matrix:');for i := 1 to 3 dobeginfor j := 1 to 3 dowrite(matrix[i, j]:4);writeln;end;
for i := 1 to 3 dosum := sum + matrix[i, i];
writeln('Sum of the main diagonal elements: ', sum);end.
program MainDiagonalSum;
var
matrix: array[1..3, 1..3] of integer;
i, j, sum: integer;
begin
sum := 0;
writeln('Enter elements of the matrix:');
for i := 1 to 3 do
for j := 1 to 3 do
begin
write('matrix[', i, '][', j, ']: ');
readln(matrix[i, j]);
end;
writeln('Matrix:');
for i := 1 to 3 do
begin
for j := 1 to 3 do
write(matrix[i, j]:4);
writeln;
end;
for i := 1 to 3 do
sum := sum + matrix[i, i];
writeln('Sum of the main diagonal elements: ', sum);
end.