Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 22:51, 11 December 2014
, 9 years ago→{{header|REXX}}: added whitespace and comments, changed indentations and comments, changed default, added boxed comments.
m (→{{header|REXX}}: removed STYLE from the PRE html tag.) |
(→{{header|REXX}}: added whitespace and comments, changed indentations and comments, changed default, added boxed comments.) |
||
Line 1,398:
=={{header|REXX}}==
<lang rexx>/*REXX program
call bloat /*the BLOAT procedure does all allocations.*/
exit
/*─────────────────────────BLOAT subroutine─────────────────────────────*/
bloat: procedure; say /*"PROCEDURE" makes this a ··· procedure. */
say 'Enter two positive integers (a 2-dimensional array will be created).'
pull n m . /*
/*
@.=' ·
do k=1 for m /* "
▲ if random()//7==0 then a.j.k=j'_'k /*populate every 7th random*/
end /*k*/
end /*j*/
do r=1 for n;
do c=1 for m /*construct row one column at a time. */
_=_ right(@.r.c,4) /*append a nice-aligned column to the line.*/
do c=1 for m▼
end /*kk*/
/*╔════════════════════════════════════════════════════════════════════╗
║ When the RETURN
║ array @ is "de─allocated", that is, it's no longer defined, and ║
▲ /*PROCEDURE in this case), the array A. is*/
║ the array's storage is now free for other REXX variables. If the ║
║ BLOAT subroutine didn't have a "PROCEDURE" on that statement,║
▲ /*defined, and the memory that the array */
║ the array @ would've been left intact. The same
║ performed by a DROP statement (an example is shown below). ║
╚════════════════════════════════════════════════════════════════════╝*/
drop
▲ /*The same effect is performed by a DROP. */
'''output''' when the following input is entered after the prompt message: <tt> 30 15 </tt>
<pre>
·
·
· 5~2 ·
·
·
·
·
·
15~1
16~1 ·
·
·
·
·
·
·
·
27~1 · 27~3 ·
·
·
·
</pre>
|