PROGRAM ARRAY KELOMPOK 3
❖ Program Array Dimensi 1 :
#include <iostream>
using namespace std;
int main() {
cout << "Array Dimensi 1 :\n";
cout << "=================\n";
int angka[5] = {1, 2, 3, 4, 5};
for (int a=0; a<5; a++) {
cout << angka[a] << ",";
}
}
❖ Program Array Dimensi 2 :
#include <iostream>
using namespace std;
int main() {
cout << "Array Dimensi 2 :\n";
cout << "=================\n";
int nilai[3][2] = {
{1, 2},
{3, 4},
{5, 6}
};
for (int b=0; b<3; b++) {
for (int c=0; c<2; c++) {
cout << nilai[b][c] << " | ";
}
cout << endl;
}
}
❖ Program Array Dimensi 3 :
#include <iostream>
using namespace std;
int main() {
cout << "Array Dimensi 3 :\n";
cout << "=================\n";
int number[2][2][3] = {
{ {1, 2, 3},
{4, 5, 6} },
{ {7, 8, 9},
{0, 0, 0}
}
};
for (int d=0; d<2; d++) {
for (int e=0; e<2; e++) {
for (int f=0; f<3; f++) {
cout << number[d][e][f] << " | ";
}
cout << endl;
}
}
}
❖ Contoh Program 1 :
#include<iostream>
using namespace std;
int main() {
int nilai[4][2] = {
{90, 85},
{88, 92},
{75, 80},
{60, 91}
};
cout << " Nilai Mahasiswa:\n";
cout << " ================\n" <<endl;
for (int i=0; i<4; i++) {
cout << " Mahasiswa "<<i+1 <<": ";
for (int j=0; j<2; j++) {
cout << nilai[i][j] << " ";
}
cout << endl;
}
return 0;
}
❖ Contoh Program 2 :
#include <iostream>
using namespace std;
int main() {
string nama[4] = {
{" Rido Veliks Papasoka "},
{" Refi William Imanuel Usmany"},
{" Nadine Switly Valeria Talla"},
{" Juan Yesaya Wattimena "}
};
string npm[4] = {
{"12155201240135"},
{"12155201240129"},
{"12155201240118"},
{"12155201240098"}
};
cout << " Anggota Kelompok 3 : \n";
cout << " =====================\n"<<endl;
for (int i=0; i<4; i++) {
cout << nama[i] << " : " << npm[i] << endl;
}
return 0;
}
❖ Program Gabungan Dimensi 1, 2, 3 :
#include <iostream>
using namespace std;
int main() {
cout << "Array Dimensi 1 :\n";
cout << "=================\n";
int angka[5] = {1, 2, 3, 4, 5};
for (int a=0; a<5; a++) {
cout << angka[a] << ",";
}
cout << endl;
cout << endl;
cout << "Array Dimensi 2 :\n";
cout << "=================\n";
int nilai[3][2] = {
{1, 2},
{3, 4},
{5, 6}
};
for (int b=0; b<3; b++) {
for (int c=0; c<2; c++) {
cout << nilai[b][c] << " | ";
}
cout << endl;
}
cout << endl;
cout << "Array Dimensi 3 :\n";
cout << "=================\n";
int number[2][2][3] = {
{ {1, 2, 3},
{4, 5, 6} },
{ {7, 8, 9},
{0, 0, 0}
}
};
for (int d=0; d<2; d++) {
for (int e=0; e<2; e++) {
for (int f=0; f<3; f++) {
cout << number[d][e][f] << " | ";
}
cout << endl;
}
}
return 0;
}