Write a program that calculates the sum of the diagonal elements of a square matrix (5.5).

program zz1;
const n = 5; // set the number of elements in the array
var i, j, k: integer; // set variables of integer type
m: array [1..n, 1..n] of integer;
begin
for i: = 1 to n do
for j: = 1 to n do // get numbers and write them into an array
m [i, j]: = random (11);
for i: = 1 to n do // display the resulting array on the screen
begin
for j: = 1 to n do
write (m [i, j]: 4);
writeln;
end;
for i: = 1 to n do
for j: = 1 to n do
if (i = j) or (i = n – j + 1) then k: = k + m [i, j];
write (‘sum of array elements on diagonals =’, k); // display the answer
end.



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.