//program perkalian matriks ordo 2x2 dengan 2x2
#include
using namespace std;
int main(){
int matriks1[2][2];
int matriks2[2][2];
int hasil[2][2];
int temp;
//input matriks 1
for (int i=0;i<2;i++){
for (int j=0;j<2;j++){
cout << "Nilai matriks pertama baris ke-" << i+1 << "Kolom ke-" << j+1 << " : " ;
cin >> matriks1[i][j];
}
}
//input matriks 2
for (int i=0;i<2;i++){
for (int j=0;j<2;j++){
cout << "Nilai matriks pertama baris ke-" << i+1 << "Kolom ke-" << j+1 << " : " ;
cin >> matriks2[i][j];
}
}
cout << endl << "Matriks 1\n" ;
//ouput matriks 1
for (int i=0;i<2;i++){
for (int j=0;j<2;j++){
cout << matriks1[i][j] << " ";
}
cout << endl ;
}
cout << endl << "Matriks 2\n" ;
//ouput matriks 2
for (int i=0;i<2;i++){
for (int j=0;j<2;j++){
cout << matriks2[i][j] << " ";
}
cout << endl ;
}
//proses perkalian matriks 1 dan 2
for (int i=0;i<2;i++){
for (int j=0;j<2;j++){
hasil[i][j]=0;
for (int k=0;k<2;k++){
temp = matriks1[i][k] * matriks2[k][j];
hasil[i][j]=hasil[i][j] + temp;
}
}
}
cout << endl << "Hasil :\n" ;
//hasil kali matriks 1 dan 2
for (int i=0;i<2;i++){
for (int j=0;j<2;j++){
cout << hasil[i][j] << " ";
}
cout << endl ;
}
}
Komentar
Posting Komentar