matrik perkalian

#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 matrik A
cout<<“Silahkan Input Matrik A:\n”;
cout<<“———————–\n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<“Matrik “<<(i+1)<<“,”<<(j+1)<<“:”;
cin>>A[i][j];
}
}
//cetak matrik 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 matrik B
cout<<“Silahkan Inputkan Martik B:\n”;
cout<<“————————–\n”;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<“Matrik “<<(i+1)<<“,”<<(j+1)<<“:”;
cin>>B[i][j];
}
}
//cetak matrik 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();
}

Leave a comment

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