Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 00:48, 22 July 2007
, 16 years agoUndo revision 6520 by Special:Contributions/ZawUjj (User talk:ZawUjj)
mNo edit summary |
(Undo revision 6520 by Special:Contributions/ZawUjj (User talk:ZawUjj)) |
||
Line 1:
{{task}}
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 oputput that element. Finally destroy the array if not done by the language itself.
Line 27:
==[[C plus plus|C
[[Category:C plus plus]]
With language built-in facilities:
Line 44:
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1;
array[i] = array_data
// write element
Line 125:
Double[][] array = new Double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is "
} catch(IOException e) { }
Line 140:
sub make_array($ $){
# get array sizes from provided params, but force numeric value
my $x = ($_[0] =~ /^\d
my $y = ($_[0] =~ /^\d
# define array, then add multi-dimensional elements
|