Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 20:22, 5 June 2012
, 12 years ago→{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~
m (→{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~) |
|||
Line 1,185:
=={{header|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
/*no more array named A. at this point.*/
exit
/*-------------------------BLOAT subroutine-----------------------------*/
bloat: procedure; say▼
▲bloat: procedure
say 'Enter two positive integers (a 2-dimensional array will be created).'
say
Line 1,206 ⟶ 1,200:
a.='~' /*default value for all elements so far. */
/*this ensures every element has a value. */
do j=1 for n
do k=1 for m
if random()//7==0 then a.j.k=j'_'k
end /*k*/
end /*j*/
do jj=1 for n /*now, display the array to the console. */
_=
do kk=1 for m
_=_ right(a.jj.kk,4)
end /*kk*/
say _
end /*jj*/
/*when the RETURN is executed (from a */
/*PROCEDURE in this case), the array A. is*/
Line 1,234 ⟶ 1,225:
/*The same effect is performed by a DROP. */
drop a.
return</lang>
'''output''' when the following input is entered after the prompt message: <tt> 30 15 </tt>
<pre style="height:30ex;overflow:scroll">
~ 1_2 ~ ~ ~ ~ ~ 1_8 1_9 1_10 1_11 ~ ~ ~ ~
|