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

m
Spelling/grammar/aesthetics
(→‎{{header|J}}: Amplified dynamic qualities.)
m (Spelling/grammar/aesthetics)
Line 1:
{{task}}
{{data structure}}
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 oputputoutput that element. Finally destroy the array if not done by the language itself.
 
=={{header|Ada}}==
Line 121:
 
=={{header|IDL}}==
The following is only for demonstration. No real program should just assume that the user input is valid, integer, large enough etc.
just assume that the user input is valid, integer, large enough etc.
read, x, prompt='Enter x size:'
Line 185 ⟶ 184:
'''Interpreter:''' [[Perl]] 5.x
 
Predefining an array (or multi-dimension array) size is unnecessary, Perl dynamically resizes the array to meet the requirements. Of course I'm assuming that the user is entering array size 0 based.
 
sub make_array($ $){
Line 196 ⟶ 195:
$array[0][0] = 'X '; # first by first element
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x); # sixth by eighth element, if the max size is big enough
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x); # thirteeththirteenth by sixteenth element, if the max size is big enough
# loop through the elements expected to exist base on input, and display the elements contents in a grid
Line 221 ⟶ 220:
0 -> ar;
 
Pop11 is garbage collected so there is no need to destroy array. However, the array is live as long as variable ar references it. The last assignment makes sure that we loose all our references to the array turning it into garbage.
the array is live as long as variable ar references it. The last
assignment makes sure that we loose all our references to the array
turning it into garbage.
 
Pop11 arrays may have arbitrary lower bounds, since we are given only size we create 0 based array.
size we create 0 based array.
 
=={{header|Python}}==
Anonymous user