PERKALIAN 2 MATRIKS MENGGUNAKAN ARRAY
1.
Perkalian
matriks ordo 2x2 manual
#include<iostream>
using namespace
std;
int main () {
int A[2][2]={{1,2},{3,4}};
int B[2][2]={{5,6},{7,8}};
int c,d;
int w,x,y,z;
cout<<endl;
cout<<"Matriks
A"<<endl;
for(c=0;c<2;c++){
for(d=0;d<2;d++){
cout<<" "<<A[c][d];
}
cout<<endl;
}
cout<<endl;
cout<<"Matriks
B"<<endl;
for(c=0;c<2;c++){
for(d=0;d<2;d++){
cout<<" "<<B[c][d];
}
cout<<endl;
}
cout<<endl;
cout<<"Perkalian Matriks
AxB"<<endl;
w=((A[0][0]*B[0][0])+(A[0][1]*B[1][0]));
x=((A[0][0]*B[0][1])+(A[0][1]*B[1][1]));
y=((A[1][0]*B[0][0])+(A[1][1]*B[1][0]));
z=((A[1][0]*B[0][1])+(A[1][1]*B[1][1]));
cout<<" "<<w<<" "<<" "<<x<<endl;
cout<<" "<<y<<" "<<" "<<z;
}
22. Perkalian matriks dengan di input
#include<iostream>
using namespace
std;
int main () {
int A[2][2]={{1,2},{3,4}};
int B[2][2]={{5,6},{7,8}};
int C[2][2];
int c,d,e;
cout<<endl;
cout<<"Matriks
A"<<endl;
for(c=0;c<2;c++){
for(d=0;d<2;d++){
cout<<" "<<A[c][d];
}
cout<<endl;
}
cout<<endl;
cout<<"Matriks
B"<<endl;
for(c=0;c<2;c++){
for(d=0;d<2;d++){
cout<<" "<<B[c][d];
}
cout<<endl;
}
cout<<endl;
for(c=0;c<2;c++){
for(d=0;d<2;d++){
for(e=0;e<2;e++){
C[c][d]=(A[c][e]*B[e][d]+A[e][c]*B[d][e]);
}
}
}
cout<<endl;
cout<<"Hasil perkalian
Matriks AxB Adalah";
cout<<endl;
for(c=0;c<2;c++){
for(d=0;d<2;d++){
C[c][d]=0;
for(e=0;e<2;e++)
C[c][d]=C[c][d]+A[c][e]*B[e][d];
cout<<" "<<C[c][d];
}
cout<<endl;
}
}
33.
Perkalian axa
#include<iostream>
using namespace
std;
int main () {
int A[10][10];
int B[10][10];
int C[10][10];
int a,c,d,e,f;
cout<<endl;
cout<<"Untuk perkalian
axa"<<endl;
cout<<endl;
cout<<"Masukkan jumlah
baris = ";
cin>>a;
cout<<endl;
cout<<"Matriks
A["<<a<<"]["<<a<<"]"<<endl;
cout<<endl;
for(c=0;c<a;c++){
for(d=0;d<a;d++){
cout<<"Masukkan
nilai matriks A["<<c<<"]["<<d<<"]=
";
cin>>A[c][d];
cout<<endl;
}
}
cout<<"Jadi, Matriks A
adalah"<<endl;
for(c=0;c<a;c++){
for(d=0;d<a;d++){
cout<<" "<<A[c][d];
}
cout<<endl;
}
cout<<endl;
cout<<"Matriks
B["<<a<<"]["<<a<<"]"<<endl;
cout<<endl;
for(c=0;c<a;c++){
for(d=0;d<a;d++){
cout<<"Masukkan
nilai matriks B["<<c<<"]["<<d<<"]=
";
cin>>B[c][d];
cout<<endl;
}
}
cout<<"Jadi, Matriks B
adalah"<<endl;
for(c=0;c<a;c++){
for(d=0;d<a;d++){
cout<<" "<<B[c][d];
}
cout<<endl;
}
cout<<endl;
for(c=0;c<a;c++){
for(d=0;d<a;d++){
for(e=0;e<a;e++){
C[c][d]=(A[c][e]*B[e][d]+A[e][c]*B[d][e]);
}
}
}
cout<<endl;
cout<<"Hasil perkalian
Matriks AxB Adalah";
cout<<endl;
for(c=0;c<a;c++){
for(d=0;d<a;d++){
C[c][d]=0;
for(e=0;e<a;e++)
C[c][d]=C[c][d]+A[c][e]*B[e][d];
cout<<" "<<C[c][d];
}
cout<<endl;
}
}
Tidak ada komentar:
Posting Komentar