How to resolve the algorithm Identity matrix step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Identity matrix step by step in the ERRE programming language

Table of Contents

Problem Statement

Build an   identity matrix   of a size known at run-time.

An identity matrix is a square matrix of size n × n, where the diagonal elements are all 1s (ones), and all the other elements are all 0s (zeroes).

I

n

=

[

1

0

0

0

0

1

0

0

0

0

1

0

0

0

0

1

]

{\displaystyle I_{n}={\begin{bmatrix}1&0&0&\cdots &0\0&1&0&\cdots &0\0&0&1&\cdots &0\\vdots &\vdots &\vdots &\ddots &\vdots \0&0&0&\cdots &1\\end{bmatrix}}}

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Identity matrix step by step in the ERRE programming language

Source code in the erre programming language

PROGRAM IDENTITY

!$DYNAMIC
DIM A[0,0]

BEGIN
  PRINT(CHR$(12);) ! CLS
  INPUT("Matrix size",N%)
  !$DIM A[N%,N%]
  FOR I%=1 TO N% DO
    A[I%,I%]=1
  END FOR
! print matrix
  FOR I%=1 TO N% DO
    FOR J%=1 TO N% DO
      WRITE("###";A[I%,J%];)
    END FOR
    PRINT
  END FOR
END PROGRAM

  

You may also check:How to resolve the algorithm Word wheel step by step in the Pascal programming language
You may also check:How to resolve the algorithm CRC-32 step by step in the PowerBASIC programming language
You may also check:How to resolve the algorithm Singly-linked list/Element insertion step by step in the Axe programming language
You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the C# programming language
You may also check:How to resolve the algorithm Musical scale step by step in the Locomotive Basic programming language