#include<iostream.h>
void main()
{
int i,j,k,kolm,barm,barn,koln;
int data1[25][25],data2[25][25],hasil[25][25];
do
{
cout<<"Program Perkalian Matrix"<<endl;
cout<<endl;
cout<<"Input Matrix M: "<<endl;
cout<<"Jml kolom M: "; cin>>kolm;
cout<<"Jml baris M: "; cin>>barm;
cout<<"Input Matrix N: "<<endl;
cout<<"Jml kolom N: "; cin>>koln;
cout<<"Jml baris N: "; cin>>barn;
}
while (kolm!=barn);
cout<<endl;
for (i=1; i<=barm; i++)
{
for (j=1; j<=kolm; j++)
{
cout<<"Data M ["<<i<<","<<j<<"]: "; cin>>data1[i][j];
}
}
cout<<endl;
for (i=1; i<=barn; i++)
{
for (j=1; j<=koln; j++)
{
cout<<"Data N ["<<i<<","<<j<<"]: "; cin>>data2[i][j];
}
}
for (i=1; i<=barm; i++)
{
for (j=1; j<=koln; j++)
{
for (k=1; k<=kolm; k++)
{
hasil[i][j]=hasil[i][j] + data1[i][k] * data2[k][j];
}
}
}
cout<<endl;
cout<<"Hasil Perkalian Matrix M x N: "<<endl;
for (i=1; i<=barm; i++)
{
for (j=1; j<=koln; j++)
{
cout<<hasil[i][j]<<" ";
}
cout<<endl;
}
}
Tidak ada komentar:
Posting Komentar