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]] 



PROC PrintMatrix(INT ARRAY m BYTE size)
  BYTE x,y
  INT v
 
  FOR y=0 TO size-1
  DO
    FOR x=0 TO size-1
    DO
      v=m(x+y*size)
      IF v<10 THEN Put(32) FI
      PrintB(v) Put(32)
    OD
    PutE()
  OD
RETURN
 
INT FUNC SumBelowDiagonal(INT ARRAY m BYTE size)
  BYTE x,y
  INT sum
 
  sum=0
  FOR y=1 TO size-1
  DO
    FOR x=0 TO y-1
    DO
      sum==+m(x+y*size)
    OD
  OD
RETURN (sum)
 
PROC Main()
  INT sum
  INT ARRAY 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]
 
  PrintE("Matrix")
  PrintMatrix(m,5)
  PutE()
  sum=SumBelowDiagonal(m,5)
  PrintF("Sum below diagonal is %I",sum)
RETURN