-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultidimensi-array.cpp
74 lines (62 loc) · 1.44 KB
/
multidimensi-array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// lawaTeko, Kairatu, Mahu
// membuat Multidimensi array khususnya 2D dan 3D, maaf jika ada sedikit kesalahan pengkodean
#include <iostream>
using namespace std;
int main() {
/* Pada dasarnya array multidimensi ini seperti Matriks
Misalnya, array 2D dapat dianggap sebagai matriks dengan baris dan kolom,
di mana setiap elemen dapat diakses menggunakan dua indeks:
satu untuk baris dan satu untuk kolom.
*/
// Array 2D
int array2D[2][2] = {
{1, 2},
{3, 4}
};
cout << "array 2D :" << endl;
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
cout << array2D[i][j] << " ";
}
cout << endl;
}
/* cout << "array 2D :" << endl;
cout << array2D[0][0] << " " << array2D[0][1] << endl;
cout << array2D[1][0] << " " << array2D[1][1] << endl;
*/
cout << endl;
// Array 3D
int array3D[3][3][2] = {
{
{1, 2},
{3, 4},
{5, 6}
},
{
{5, 6},
{7, 8},
{9, 10}
},
{
{11, 12},
{13, 14},
{15, 16}
}
};
cout << "array 3D :" << endl;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 2; k++){
cout << array3D[i][j][k] << " ";
}
cout << endl;
}
cout << "------" << endl;
}
/* cout << "array 3D :" << endl;
cout << array3D[0][0][0] << " " << array3D[0][0][1] << endl;
cout << array3D[0][1][0] << " " << array3D[0][1][1] << endl;
cout << array3D[1][0][0] << " " << array3D[1][0][1] << endl;
cout << array3D[1][1][0] << " " << array3D[1][1][1] << endl;*/
return 0;
}