Program Perkalian Matrik pada C++


#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();
//masukkan matrix A
cout<<“Silahkan input matrik A : \n”;
cout<<“————————- \n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<“Elemen ke “<<(i+1)<<“,”<<(j+1)<<” : “;
cin>>A[i][j];
}
}

//cetak matrix A
cout<<“\nMatrik A : \n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<setw(4)<<A[i][j];
}
cout<<endl;
}
cout<<endl;
//masukkan matriks B
cout<<“Silahkan input matrik B : \n”;
cout<<“————————- \n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<“Elemen ke “<<(i+1)<<“,”<<(j+1)<<” : “;
cin>>B[i][j];
}
}
//cetak matrix B
cout<<“\nMatrik B : \n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<setw(4)<<B[i][j];
}
cout<<endl;
}
//Operasi Perkalian
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
C[i][j]=0;
for (k=0;k< 3;k++)
{
C[i][j]+= A[i][k]*B[k][j];
}
}
}
//Menampilkan hasil
cout<<“\nMatrik C, Hasil : \n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<setw(4)<<C[i][j];
}
cout<<endl;
}
cout<<endl;
getch();
}

Advertisements

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s