Task

Find and display the sum of elements that are below the main diagonal of a matrix.

The matrix should be a square matrix.



 ───   Matrix to be used:   ───


     [[1,3,7,8,10],
      [2,4,16,14,4],
      [3,1,9,18,11],
      [12,14,17,18,20],
      [7,1,3,9,5]] 



constant M = {{ 1,  3,  7,  8, 10},
              { 2,  4, 16, 14,  4},
              { 3,  1,  9, 18, 11},
              {12, 14, 17, 18, 20},
              { 7,  1,  3,  9,  5}}
atom res = 0
integer height = length(M)
for row=1 to height do
    integer width = length(M[row])
    if width!=height then crash("not square") end if
    for col=1 to row-1 do
        res += M[row][col]
    end for
end for
?res
