Monday, 24 May 2010

N-Dimensional Array

N-dimensional array is an array that has two or more indexes. To understand the concept of n-dimensional array, see the picture below.

To declare two-dimensional array that can hold six character, we can us this statement :

Type

    TwoDimensionalArray = array[1..2, 1..3] of char;

Var

    TheData : TwoDimensionalArray;

Or you can use this statement :

Var

    TheData : array[1..2, 1..3] of char;

To access an element in two-dimensional array use this syntax :

ArrayVariableName[ArrayIndex1,ArrayIndex2];

Example :

TheData[1,3] := ‘A’;

Writeln(TheData[1,3]);

Readln(TheData[1,3]);

Example program :

program Project1;
{$APPTYPE CONSOLE}
uses
   SysUtils;
var
   i, j : integer;
   TheData : array[1..2, 1..3] of char;
begin
   //assigning values to array
   TheData[1,1] := 'A';
   TheData[1,2] := 'B';
   TheData[1,3] := 'C';
   TheData[2,1] := 'D';
   TheData[2,2] := 'E';
   TheData[2,3] := 'F';
   for i := 1 to 2 do
    begin
      for j := 1 to 3 do writeln(TheData[i,j]);
    end;
   readln;
end.

You can download the complete code here.

How to declare a three-dimensional array and to use it in a program ?

4 comments:

  1. codingnya mantafff mas, walau mudenk dikit2. cocok untuk mereka yang lagi ada tugas Array nich

    ReplyDelete
  2. thanks, kunjungan balik nih . . .tukeran review alexa yukk . .

    ReplyDelete
  3. gak mudeng tentang ... karena bukan bidangnya pak like. ...

    ReplyDelete
    Replies
    1. s The best and a lot of secret drop-shipping suppliers in the world which will provide your products globally available for you directly to your customers doors. Also get the best drop-shipping manufacturer on your organization.

      Delete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.