Tuesday, 25 May 2010

3-Dimensional Array

3-dimensional array is an array that has three indexes. To understand the concept of 3-dimensional array, see the picture below.

To declare 3-dimensional array that can hold 24 character, we can us this statement :

Type

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

Var

    TheData : TwoDimensionalArray;

Or you can use this statement :

Var

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

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

ArrayVariableName[ArrayIndex1, ArrayIndex2, ArrayIndex3];

Example :

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

Writeln(TheData[1,3,4]);

Readln(TheData[1,3,4]);

Example :


program Project1;
{$APPTYPE CONSOLE}
uses
   SysUtils;

var
   i, j, k : integer;
   Thedata : array[1..2, 1..3, 1..2] of char;
begin
  TheData[1,1,1] := 'A';
  TheData[1,1,2] := 'B';
  TheData[1,2,1] := 'C';
  TheData[1,2,2] := 'D';
  TheData[1,3,1] := 'E';
  TheData[1,3,2] := 'F';
  TheData[2,1,1] := 'G';
  TheData[2,1,2] := 'H';
  TheData[2,2,1] := 'I';
  TheData[2,2,2] := 'J';
  TheData[2,3,1] := 'K';
  TheData[2,3,2] := 'L';
  for i := 1 to 2 do
   begin
     for j := 1 to 3 do
       begin
         for k := 1 to 2 do writeln(TheData[i,j,k]);
       end;
   end;
  readln; 
end.

You can download the complete code here.

4 comments:

  1. sip deh Mas, saya pelajari dulu...

    ReplyDelete
  2. wah gile, code apaan nih sob mumuet dah lihatnya

    ReplyDelete
  3. aq masih blogger pemula, ngutak ngatik kode html blog aja masih bingung apa lagi code2 ginian, hebat kamu sob

    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.