How to resolve the algorithm Create a two-dimensional array at runtime step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Create a two-dimensional array at runtime step by step in the PL/I programming language

Table of Contents

Problem Statement

Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Create a two-dimensional array at runtime step by step in the PL/I programming language

Source code in the pl/i programming language

/* First way using a controlled variable: */

declare A(*,*) float controlled;
get list (m, n);
allocate A(m,n);
get list (A);
put skip list (A);

/* The array remains allocated until the program terminates, */
/* or until explicitly destroyed using a FREE statement.     */

free A;


 6.00000E+0000           5.00000E+0000           4.00000E+0000           3.00000E+0000           2.00000E+0000          
 1.00000E+0000

/* Second way using a BEGIN block: */

get list (m, n);
begin;
   declare A(m, n) float;
   get list (A);
   put skip list (A);
end;

/* The array is automatically destroyed when the block terminates. */

 1.00000E+0000           2.00000E+0000           3.00000E+0000           4.00000E+0000           5.00000E+0000          
 6.00000E+0000           7.00000E+0000           8.00000E+0000           9.00000E+0000           1.00000E+0001          
 1.10000E+0001           1.20000E+0002

/* Third way using a PROCEDURE block: */

get list (m, n);
call S (m, n);
S: procedure (m, n);
   declare A(m, n) float;
   get list (A);
   put skip list (A);
end S;

/* The array is automatically destroyed when the procedure terminates. */

 1.00000E+0000           2.00000E+0000           3.00000E+0000           4.00000E+0000           5.00000E+0000          
 6.00000E+0000           7.00000E+0000           8.00000E+0000           9.00000E+0000           1.00000E+0001          
 1.10000E+0001           1.20000E+0001           1.30000E+0001           1.40000E+0001           1.50000E+0001          
 1.60000E+0001           1.70000E+0001           1.80000E+0001           1.90000E+0001           2.00000E+0001

  

You may also check:How to resolve the algorithm Bitmap/Read a PPM file step by step in the PL/I programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the PL/I programming language
You may also check:How to resolve the algorithm Stack traces step by step in the PL/I programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the PL/I programming language
You may also check:How to resolve the algorithm Recaman's sequence step by step in the PL/I programming language