Nama : Miranda Stella Yosefin
NIM. : 16117059
#include <iostream>
using namespace std;
int main () {
//deklarasi
int barisM1, kolomM1, barisM2, kolomM2, temp, i, j, M1[10][10], M2[10][10], Mhasil[10][10];
//memaskukkan jumlah baris dan kolom M1
cout<<"Jumlah Baris dan kolom M1\n";
cout<<"Baris : ";
cin>>barisM1;
cout<<"Kolom : ";
cin>>kolomM1;
cout<<endl;
cout<<"Elemen Matrik \n";
for( i=0; i<barisM1; i++ ){
for( j=0; j<kolomM1; j++ ){
cin>>M1[i][j];
}
}
cout<<endl;
for( i=0; i<barisM1; i++ ){
for( j=0; j<kolomM1; j++ ){
cout<<M1[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
//memaskukkan jumlah baris dan kolom M2
cout<<"Jumlah dan Baris kolom M2\n";
cout<<"Baris : ";
cin>>barisM2;
cout<<"Kolom : ";
cin>>kolomM2;
cout<<endl;
cout<<"Elemen Matrik \n";
for( i=0; i<barisM2; i++ ){
for( j=0; j<kolomM2; j++ ){
cin>>M2[i][j];
}
}
cout<<endl;
for( i=0; i<barisM2; i++ ){
for( j=0; j<kolomM2; j++ ){
cout<<M2[i][j]<<" ";
}
cout<<endl;
}
if (kolomM1==barisM2){
for (i=0 ;i<barisM2; i++){
for (j=0;j<kolomM2; j++){
Mhasil[i][j]=0;
for (int z=0;z<barisM2;z++){
temp=M1[i][z]*M2[z][j];
Mhasil[i][j]=Mhasil[i][j]+temp;
}
}
}
// tampilkan hasil penjumlahan matrik
cout<<"Hasil Perkalian matriks : \n";
for( i=0; i<barisM2; i++ ){
for( j=0; j<kolomM2; j++ ){
cout<<Mhasil[i][j]<<"\t";
}
cout<<endl;
}
}
else{
cout<<"Matriks Tidak Dapat Dikalikan";
}
return 0;
}