How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the Seed7 programming language

Table of Contents

Problem Statement

Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";

const proc: main is func
  local
    var integer: sum is 0;
    var integer: i is 0;
    var integer: j is 0;
    const array array integer: m is [] ([] ( 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));
  begin
    for i range 2 to length(m) do
      for j range 1 to i - 1 do
        sum +:= m[i][j];
      end for;
    end for;
    writeln(sum);
  end func;

  

You may also check:How to resolve the algorithm Square but not cube step by step in the Nim programming language
You may also check:How to resolve the algorithm Jewels and stones step by step in the 11l programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the Batch File programming language
You may also check:How to resolve the algorithm Strip comments from a string step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Program name step by step in the Lingo programming language