dimensi jika diketahui data inputan
array sebagai berikut :
Matriks Pertama :
1 2
4 5
Matriks Kedua :
6 5
3 2
Jawab :
#include<iostream.h>
#include<conio.h>
int main()
{
int A[2][2];
int B[2][2];
int C[2][2];
cout<<"Perkalian array 2 Dimensi [2][2]x[2][2]"<<endl;
cout<<"Elemen-elemen Matriks A";
for(int i=0; i<=1; i++)
{
for(int j=0; j<=1; j++)
{
cout<<"Masukkan Elemen Matriks ["<<i<<","<<j<<"] : ";
cin>>A[i][j];
}
}
cout<<"\n\nElemen Matriks B\n";
for(i=0; i<=1; i++)
{
for(int j=0; j<=1; j++)
{
cout<<"Masukkan Elemen Matriks ["<<i<<","<<j<<"] : ";
cin>>B[i][j];
}
}
//Menampilkan Matriks A
cout<<"\nMatriks A\n";
for(i=0; i<=1; i++)
{
for(int j=0; j<=1; j++)
{
cout<<" "<<A[i][j];
}cout<<"\n";
}
//Menampilkan Matriks B
cout<<"\nMatriks B\n";
for(i=0; i<=1; i++)
{
for(int j=0; j<=1; j++)
{
cout<<" "<<B[i][j];
}cout<<"\n";
}
//Menghitung Matriks C=A*B
cout<<"\n\nPerkalian Matriks C=A*B\n";
cout<<"\n";
for(i=0; i<=1; i++)
{
for(int j=0; j<=1; j++)
{
C[i][j]=0;
for(int x=0; x<=1; x++)
{
C[i][j]+=A[i][x]*B[x][j];
}
}
}
//Menampilkan Matriks C
for(i=0; i<=1; i++)
{
for(int j=0; j<=1; j++)
{
cout<<" "<<C[i][j];
}cout<<"\n";
}
return 0;
}
HASIL CODE :
Tidak ada komentar:
Posting Komentar