#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
void main()
{
int A[3][3],B[3][3],C[3][3],i,j,k;
clrscr();
cout<<"Silahkan input matrik A : "<<endl;
cout<<"------------------------- "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<"Data ke "<<(i+1)<<","<<(j+1)<<" : ";
cin>>A[i][j];
}
}
//cetak matrix A
cout<<endl;
cout<<"Matrik A : "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<setw(4)<<A[i][j];
}
cout<<endl;
}
cout<<endl;
//masukkan matriks B
cout<<"Silahkan input matrik B : "<<endl;
cout<<"------------------------- "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<"Data ke "<<(i+1)<<","<<(j+1)<<" : ";
cin>>B[i][j];
}
}
//cetak matrix B
cout<<endl;
cout<<"Matrik B : "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<setw(4)<<B[i][j];
}
cout<<endl;
}
//Operasi Perkalian
for (i=0;i<2;i++)
{
for (j=0;j<2;j++)
{
C[i][j]=0;
for (k=0;k<2;k++)
{
C[i][j]+= A[i][k]*B[k][j];
}
}
}
//Menampilkan hasil matriks 2x2
cout<<"Matrik C, Hasil : ";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<setw(4)<<C[i][j];
}
cout<<endl;
}
cout<<endl;
getch();
}
Posting Komentar