Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 04:49, 23 January 2008
, 16 years agoSpelling/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
=={{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.
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.
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); #
# 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.
Pop11 arrays may have arbitrary lower bounds, since we are given only size we create 0 based array.
=={{header|Python}}==
|