Inisialisasi array multidimensi

Sama seperti array satu dimmensi, inisialisasi juga bisa dilakukan dengan beberapa cara yaitu :

Contoh Model 1:
int A [3] [3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Contoh Model 2:
int B [3] [3] = { {1,2,3}, {4,5,6}, {7,8,9 } } ;
 
Berikut adalah video tutorial tentang inisialisasi array multidimensi di c++

 

Berikut adalah Source code dalam video tersebut.

 

/*Modul8-3
Inisialisasi Array multidimensi
Nama : Wayan Widya Artana
NRP  : 49013035
*/

#include <iostream>
using namespace std;

int main(){

int A[3][3] = {1,2,3,4,5,6,7,8,9};
int B[3][3] = {{1,2,3},{4,5,6},{7,8,9}};

for(int i = 0; i<3 ; i++){
for(int j=0; j<3; j++){
cout<<“Elemen Matriks A indeks [“<<i<<“][“<<j<<“] = “<<A[i][j]<<endl;
}
}
B[2][1] = 19;
cout<<endl<<endl;
for(int i = 0; i<3 ; i++){
for(int j=0; j<3; j++){
cout<<“Elemen Matriks B indeks [“<<i<<“][“<<j<<“] = “<<B[i][j]<<endl;
}
}

system(“pause”);
return 0;
}


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