Create a two-dimensional array at runtime: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~)
Line 1,185: Line 1,185:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>
/*REXX program to allocate/populate/display a two-dimensional array. */


<lang rexx>/*REXX program to allocate/populate/display a two-dimensional array. */
call bloat
call bloat
/*no more array named A. at this point.*/
/*no more array named A. at this point.*/

exit
exit
/*-------------------------BLOAT subroutine-----------------------------*/

bloat: procedure; say


bloat: procedure

say
say 'Enter two positive integers (a 2-dimensional array will be created).'
say 'Enter two positive integers (a 2-dimensional array will be created).'
say
say
Line 1,206: Line 1,200:
a.='~' /*default value for all elements so far. */
a.='~' /*default value for all elements so far. */
/*this ensures every element has a value. */
/*this ensures every element has a value. */

do j=1 for n
do j=1 for n
do k=1 for m
do k=1 for m
if random()//7==0 then a.j.k=j'_'k /*populate every 7th random*/
if random()//7==0 then a.j.k=j'_'k /*populate every 7th random*/
end
end /*k*/
end
end /*j*/



do jj=1 for n /*now, display the array to the console. */
do jj=1 for n /*now, display the array to the console. */
_=''
_=
do kk=1 for m
do kk=1 for m
_=_ right(a.jj.kk,4) /*display one row at a time, align the vals*/
_=_ right(a.jj.kk,4) /*display one row at a time, align the vals*/
end
end /*kk*/
say _
say _
end
end /*jj*/

/*when the RETURN is executed (from a */
/*when the RETURN is executed (from a */
/*PROCEDURE in this case), the array A. is*/
/*PROCEDURE in this case), the array A. is*/
Line 1,234: Line 1,225:
/*The same effect is performed by a DROP. */
/*The same effect is performed by a DROP. */
drop a.
drop a.
return
return</lang>
'''output''' when the following input is entered after the prompt message: <tt> 30 15 </tt>
</lang>
Output when
<br><br>
30 15
<br><br>
is entered after the prompt message.
<pre style="height:30ex;overflow:scroll">
<pre style="height:30ex;overflow:scroll">
~ 1_2 ~ ~ ~ ~ ~ 1_8 1_9 1_10 1_11 ~ ~ ~ ~
~ 1_2 ~ ~ ~ ~ ~ 1_8 1_9 1_10 1_11 ~ ~ ~ ~