
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.
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 output that element. Finally destroy the array if not done by the language itself.

begin
    integer dimension1UpperBound, dimension2UpperBound;
    write( "upper bound for dimension 1: " );
    read( dimension1UpperBound );
    write( "upper bound for dimension 2: " );
    read( dimension2UpperBound );
 
    begin
        % we start a new block because declarations must precede statements %
        % and variables in array bounds must be from outside the block      %
        integer array matrix ( 1 :: dimension1UpperBound
                             , 1 :: dimension2UpperBound
                             );
        % set the first element - the program will crash if the user input  %
        % upper bounds less than 1                                          %
        matrix( 1, 1 ) := 3;
        % write it                                                          %
        write( matrix( 1, 1 ) );
        % the array is automatically deleted when the block ends            %
    end
 
end.