Tugas Praktikum Pertemuan II
ARRAY
e) Buatlah program untuk mencetak elemen-elemen Matriks A berukuran 3×4 yang telah diinisialisasikan. Contoh output sebagai berikut (simpan dengan nama lat2_5.cpp)
1 3 4 5
2 4 6 8
3 5 7 9

Jawab :
#include <cstdlib>
#include <iostream>
using namespace std;
void baca_matriks(int mat[10][10], int, int);
void matriks_jumlah(const int [10][10], const int[10][10], int , int , int[10][10]);
void cetak_matiks(const  int A[10][10], int, int);
void baca_matriks(int mat[10][10], int baris, int kolom){
int i, j;
for( i =0;i<baris; i++)
for(j=0;j<kolom;j++){
cout << “Data [” << (i+1) << “,” << (j+1) << “] = “;
cin >> mat[i][j];
}
}
void matriks_jumlah(const int matriks[10][10], const int matriks2[10][10], int baris, int kolom, int jumlah[10][10]){
int i, j;
for(i = 0;i<baris; i++)
for(j = 0;j<kolom;j++)
jumlah[i][j] = matriks[i][j] + matriks2[i][j];
}
void cetak_matriks(const int A[10][10], int baris, int kolom){
for(int i = 0;i<baris;i++){
for(int j = 0;j<kolom;j++)
cout << ” ” << A[i][j] ;
cout << endl;
}
}
int main(int argc, char *argv[])
{
int m, n;
int matriks1[10][10], matriks2[10][10];
int jumlah[10][10];
cout << “Banyak baris : ” ;
cin >> m;
cout << “Banyak kolom : “;
cin >> n;
cout << “Data matriks ke-1 \n”;
baca_matriks(matriks1,m,n);
cetak_matriks(matriks1,m,n);
return EXIT_SUCCESS;
}

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s