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

no edit summary
(Added BBC BASIC)
No edit summary
Line 349:
writeln("The number at place [0, 0] is ", array[0][0]);
}</lang>
 
=={{header|Delphi}}==
Dimensions are generated randomly, not input by user.
<lang delphi>program Project1;
 
{$APPTYPE CONSOLE}
 
uses
SysUtils;
var
matrix:array of array of Byte;
i,j:Integer;
begin
Randomize;
//Finalization is not required in this case, but you have to do
//so when reusing the variable in scope
Finalize(matrix);
//Init first dimension with random size from 1..10
//Remember dynamic arrays are indexed from 0
SetLength(matrix,Random(10) + 1);
//Init 2nd dimension with random sizes too
for i := Low(matrix) to High(matrix) do
SetLength(matrix[i],Random(10) + 1);
 
//End of code, the following part is just output
Writeln(Format('Total amount of columns = %.2d',[Length(matrix)]));
for i := Low(matrix) to High(matrix) do
Writeln(Format('Column %.2d = %.2d rows',[i,Length(matrix[i])]));
 
Readln;
end.
</lang>
 
Test run:
<pre>
Total amount of columns = 10
Column 00 = 04 rows
Column 01 = 08 rows
Column 02 = 09 rows
Column 03 = 05 rows
Column 04 = 01 rows
Column 05 = 04 rows
Column 06 = 07 rows
Column 07 = 04 rows
Column 08 = 10 rows
Column 09 = 02 rows
</pre>
 
 
=={{header|Euphoria}}==
Anonymous user