Rumus Array Dimensi 2

Posted: 7 April 2012 in Semester II, Struktur Data, The Faculty

Secara kolom :

@M[i][j] = M[0][0] + {(j – 1) * K + (i – 1)} * L

 

Secara baris :

@M[i][j] = M[0][0] + {(i – 1) * N + (j – 1)} * L

 

Contoh soal :

Suatu Array X dideklarasikan sebagai berikut :

Float X[4][3], dengan alamat index X[0][0] berada di 0011(H) dan ukuran type data float/real = 4.

Tentukan berapa alamat array X[3][2] berdasarkan cara

pandang baris dan kolom ?

 

Diketahui :

[4] [3]

K = elemen per kolom

N = elemen per baris

4 = K

3 = N

K = Jumlah baris

N = Jumlah kolom

L = 4

 

Penyelesaian secara baris :

@M[i][j] = @M[0][0] + {(i – 1) * N + (j – 1)} * L

X[3][2] = 0011(H) + {(3 – 1) * 3 + (2 – 1)} * 4

= 0011(H) + 24 (D)

= 0011(H) + 0018 (H)

= 0029(H)

 

Penyelesaian secara kolom :

@M[i][j] = @M[0][0] + {(j – 1) * K + (i – 1)} * L

X[3][2] = 0011(H) + {(2 – 1) * 4 + (3 – 1)} * 4

= 0011(H) + 32 (D)

= 0011(H) + 0020 (H)

= 0031(H)

Comments
  1. dian octo says:

    hi,
    mo tanya nih, ttg penyelesaian secara baris & kolom.
    apa hasil perhitungannya tidak terbalik tuh??
    mohon informasinya.

    thnx a lot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s