Jawaban:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int m1[2][2],m2[2][2],hasil[2][2],pilih1;
cout<<"==>>|MENU MATRIX |<<=="<<endl;
cout<<"[1]. Penjumlahan Matrix "<<endl;
cout<<"[2]. Pengurangan Matrix "<<endl;
cout<<"[2]. Perkalian Matrix "<<endl;
cout<<"[4]. pembagian Matrix "<<endl;
cout<<"Input pillihan : ";cin>>pilih1;
system("cls");
switch(pilih1){
case 1:
cout<<"\t\tPENJUMLAHAN MATRIX "<<endl;
cout<<"\t\t___________________"<<endl;
cout<<"==>>|MATRIX A"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m1[i][j];
}
cout<<endl<<endl<<"==>>|MATRIX B "<<endl;
cin>>m2[i][j];
cout<<"==>>MATRIX A"<<endl;
for(int i=0;i<2;i++){
cout<<setw(4)<<m1[i][j]<<setw(4);
cout<<endl;
cout<<"==>>MATRIX B"<<endl;
cout<<setw(4)<<m2[i][j]<<setw(4);
cout<<endl<<endl<<"==>>MATRIX A+MATRIX B"<<endl;
hasil[i][j]=m1[i][j]+m2[i][j];
cout<<setw(4)<<hasil[i][j]<<setw(4);
break;
case 2:
cout<<"\t\tPENGURANGAN MATRIX "<<endl;
cout<<endl<<endl<<"==>>MATRIX A-MATRIX B"<<endl;
hasil[i][j]=m1[i][j]-m2[i][j];
case 3:
cout<<"\tPERKALIAN MATRIX "<<endl;
cout<<endl<<endl<<"==>>MATRIX A*MATRIX B"<<endl;
hasil[i][j]=0;
for(int k=0;k<2;k++){
hasil[i][j]+=m1[i][k]*m2[k][j];
cout<<setw(4)<<hasil[i][j];
case 4:
cout<<endl<<endl<<"==>>MATRIX A/MATRIX B"<<endl;
hasil[i][j]+=m1[i][k]/m2[k][j];
cin.ignore();
cin.get();
return 0;
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Jawaban:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int m1[2][2],m2[2][2],hasil[2][2],pilih1;
cout<<"==>>|MENU MATRIX |<<=="<<endl;
cout<<"[1]. Penjumlahan Matrix "<<endl;
cout<<"[2]. Pengurangan Matrix "<<endl;
cout<<"[2]. Perkalian Matrix "<<endl;
cout<<"[4]. pembagian Matrix "<<endl;
cout<<"Input pillihan : ";cin>>pilih1;
system("cls");
switch(pilih1){
case 1:
cout<<"\t\tPENJUMLAHAN MATRIX "<<endl;
cout<<"\t\t___________________"<<endl;
cout<<"==>>|MATRIX A"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m1[i][j];
}
}
cout<<endl<<endl<<"==>>|MATRIX B "<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m2[i][j];
}
}
system("cls");
cout<<"==>>MATRIX A"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m1[i][j]<<setw(4);
}
cout<<endl;
}
cout<<"==>>MATRIX B"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m2[i][j]<<setw(4);
}
cout<<endl;
}
cout<<endl<<endl<<"==>>MATRIX A+MATRIX B"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
hasil[i][j]=m1[i][j]+m2[i][j];
cout<<setw(4)<<hasil[i][j]<<setw(4);
}
cout<<endl;
}
break;
case 2:
cout<<"\t\tPENGURANGAN MATRIX "<<endl;
cout<<"\t\t___________________"<<endl;
cout<<"==>>|MATRIX A"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m1[i][j];
}
}
cout<<endl<<endl<<"==>>|MATRIX B "<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m2[i][j];
}
}
system("cls");
cout<<"==>>MATRIX A"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m1[i][j]<<setw(4);
}
cout<<endl;
}
cout<<"==>>MATRIX B"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m2[i][j]<<setw(4);
}
cout<<endl;
}
cout<<endl<<endl<<"==>>MATRIX A-MATRIX B"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
hasil[i][j]=m1[i][j]-m2[i][j];
cout<<setw(4)<<hasil[i][j]<<setw(4);
}
cout<<endl;
}
break;
case 3:
cout<<"\tPERKALIAN MATRIX "<<endl;
cout<<"\t\t___________________"<<endl;
cout<<"==>>|MATRIX A"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m1[i][j];
}
}
cout<<endl<<endl<<"==>>|MATRIX B "<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m2[i][j];
}
}
system("cls");
cout<<"==>>MATRIX A"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m1[i][j]<<setw(4);
}
cout<<endl;
}
cout<<"==>>MATRIX B"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m2[i][j]<<setw(4);
}
cout<<endl;
}
cout<<endl<<endl<<"==>>MATRIX A*MATRIX B"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
hasil[i][j]=0;
for(int k=0;k<2;k++){
hasil[i][j]+=m1[i][k]*m2[k][j];
}
cout<<setw(4)<<hasil[i][j];
}
cout<<endl;
}
break;
case 4:
cout<<"\tPERKALIAN MATRIX "<<endl;
cout<<"\t\t___________________"<<endl;
cout<<"==>>|MATRIX A"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m1[i][j];
}
}
cout<<endl<<endl<<"==>>|MATRIX B "<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Data["<<i<<","<<j<<"]=";
cin>>m2[i][j];
}
}
system("cls");
cout<<"==>>MATRIX A"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m1[i][j]<<setw(4);
}
cout<<endl;
}
cout<<"==>>MATRIX B"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<setw(4)<<m2[i][j]<<setw(4);
}
cout<<endl;
}
cout<<endl<<endl<<"==>>MATRIX A/MATRIX B"<<endl;
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
hasil[i][j]=0;
for(int k=0;k<2;k++){
hasil[i][j]+=m1[i][k]/m2[k][j];
}
cout<<setw(4)<<hasil[i][j];
}
cout<<endl;
}
break;
}
cin.ignore();
cin.get();
return 0;
}