0% found this document useful (0 votes)
22 views

Larik (Array) Ii: Contoh 1

The document provides 3 examples of using multi-dimensional arrays or matrices in C++. The first example initializes a 2D integer array and uses nested for loops to print out each element. The second example similarly initializes a 2D array and uses for loops to print the elements. The third example initializes a 2x2 integer matrix, takes user input to populate it, and then prints out the final matrix.

Uploaded by

islam hidayah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Larik (Array) Ii: Contoh 1

The document provides 3 examples of using multi-dimensional arrays or matrices in C++. The first example initializes a 2D integer array and uses nested for loops to print out each element. The second example similarly initializes a 2D array and uses for loops to print the elements. The third example initializes a 2x2 integer matrix, takes user input to populate it, and then prints out the final matrix.

Uploaded by

islam hidayah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LARIK (ARRAY) II

Contoh 1

#include <iostream>

#include<conio.h>

using namespace std;

int main( )

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

int baris, kolom;

for (baris=0;baris<2;baris++)

for (kolom=0;kolom<4;kolom++)

cout<<matriks[baris][kolom]<<" ";

cout<<endl;

getch();

Contoh 2

#include <stdio.h>

int main() {

int x[2][3] = {{1, 2, 3}, {4, 5, 6}}; // insialisasi data

int i, j;

for (i=0; i<2; i++) { // for yang pertama

for (j=0; j<3; j++) { // for yang kedua


printf("%d ", x[i][j]); // mencetak isi array

printf("\n"); // mencetak enter pada baris terakhir.

return 0;

Contoh 3

#include <iostream >

#include <conio.h>

using namespace std;

int matrik1[2][2];

main (){

//input matrik pertama

for (int x = 0;x<2;x++){

for (int y =0;y<2;y++){

cout <<"masukan nilai matrik pertama baris ke-"<<(x+1)<<" kolom ke-"<<(y+1)<<" : ";

cin>>matrik1[x][y];

cout<<endl;

//output matrik pertama

cout<<"Matrik Pertama :"<<endl;

for (int x = 0;x<2;x++){

for (int y =0;y<2;y++){

cout <<matrik1[x][y]<<" ";

cout<<endl;

}
}

You might also like