Berikut ini adalah pertanyaan dari samhanalkausar25 pada mata pelajaran TI untuk jenjang Sekolah Menengah Atas
Jawaban dan Penjelasan
Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.
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;
}
Semoga dengan pertanyaan yang sudah terjawab oleh goodboy9999 dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.
Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact
Last Update: Thu, 16 Feb 23