#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
char tombol;
int menu,ordo,a1,a2,a3,a4,a5,a6,a7,a8,a9,b1,b2,b3,b4,b5,b6,b7,b8,b9;
menu:
system ("color f");
system ("cls");
cout<<"\t\t OPERASI MATRIKS\n";
cout<<"\t\t ===============\n\n";
cout<<"Silahkan Pilih Ordo Matriks \n\n";
cout<<"+------------+\n";
cout<<"| 1.Ordo 2x2 |\n";
cout<<"| 2.Ordo 3x3 |\n";
cout<<"+------------+\n";
cout<<"Pilihan anda= ";cin>>ordo;
cout<<"=====================================\n";
switch(ordo)
{
case 1:
system ("cls");
cout<<"Matriks Ordo 2x2\n\n";
cout << "\tOPERASI 2 MATRIKS ORDO 2x2\n\n";
cout << "Masukkan Matrix A = \n";
cout<<"(1,1)=";cin>>a1;
cout<<"(1,2)=";cin>>a2;
cout<<"(2,1)=";cin>>a3;
cout<<"(2,2)=";cin>>a4;
cout << "\nMatriks A = \n";
cout<<"\t\t"<<a1<<"\t"<<a2<<"\n"<<"\t\t"<<a3<<"\t"<<a4<<"\n\n";
cout << "\nMatriks A^2 = \n";
cout<<"\t\t"<<a1*a1+a2*a3<<"\t"<<a1*a2+a2*a4<<"\n"<<"\t\t"<<a3*a1+a4*a3<<"\t"<<a3*a2+a4*a4<<"\n\n";
cout << "Masukkan Matrix B = \n";
cout<<"(1,1)=";cin>>b1;
cout<<"(1,2)=";cin>>b2;
cout<<"(2,1)=";cin>>b3;
cout<<"(2,2)=";cin>>b4;
cout << "\nMatriks B = \n";
cout<<"\t\t"<<b1<<"\t"<<b2<<"\n"<<"\t\t"<<b3<<"\t"<<b4<<"\n\n";
cout << "\nMatriks B^2 = \n";
cout<<"\t\t"<<b1*b1+b2*b3<<"\t"<<b1*b2+b2*b4<<"\n"<<"\t\t"<<b3*b1+b4*b3<<"\t"<<b3*b2+b4*b4<<"\n\n";
cout<<"matrix (A+B)= \n";
cout<<"\t\t"<<a1+b1<<"\t"<<a2+b2<<"\n"<<"\t\t"<<a3+b3<<"\t"<<a4+b4<<"\n\n";
cout<<"matrix (A-B)= \n";
cout<<"\t\t"<<a1-b1<<"\t"<<a2-b2<<"\n"<<"\t\t"<<a3-b3<<"\t"<<a4-b4<<"\n\n";
cout<<"matrix (B-A)= \n";
cout<<"\t\t"<<b1-a1<<"\t"<<b2-a2<<"\n"<<"\t\t"<<b3-a3<<"\t"<<b4-a4<<"\n\n";
cout<<"matrix (A*B)= \n";
cout<<"\t\t"<<a1*b1+a2*b3<<"\t"<<a1*b2+a2*b4<<"\n"<<"\t\t"<<a3*b1+a4*b3<<"\t"<<a3*b2+a4*b4<<"\n\n";
cout<<"matrix (B*A)= \n";
cout<<"\t\t"<<b1*a1+b2*a3<<"\t"<<b1*a2+b2*a4<<"\n"<<"\t\t"<<b3*a1+b4*a3<<"\t"<<b3*a2+b4*a4<<"\n\n";
cout<<"Det(A)=";
cout<<"\t\t"<<"("<<a1<<"*"<<a4<<")"<<" - "<<"("<<a2<<"*"<<a3<<")"<<"\n"<<"\t\t"<<a1*a4<<" - "<<a2*a3<<" = "<<a1*a4-a2*a3<<"\n\n";
cout<<"Det(B)=";
cout<<"\t\t"<<"("<<b1<<"*"<<b4<<")"<<" - "<<"("<<b2<<"*"<<b3<<")"<<"\n"<<"\t\t"<<b1*b4<<" - "<<b2*b3<<" = "<<b1*b4-b2*b3<<"\n\n";
cout<<"Tr (A)= \n";
cout<<"\t\t"<<"("<<a1<<"+"<<a4<<")"<<" = "<<a1+a4<<"\n\n";
cout<<"Tr (B)= \n";
cout<<"\t\t"<<"("<<b1<<"+"<<b4<<")"<<" = "<<b1+b4<<"\n\n";
break;
case 2:
system ("cls");
cout<<"Matriks Ordo 3x3\n\n";
cout << "\tOPERASI 2 MATRIKS ORDO 3x3\n\n";
cout << "Masukkan Matrix A = \n";
cout<<"(1,1)=";cin>>a1;
cout<<"(1,2)=";cin>>a2;
cout<<"(1,3)=";cin>>a3;
cout<<"(2,1)=";cin>>a4;
cout<<"(2,2)=";cin>>a5;
cout<<"(2,3)=";cin>>a6;
cout<<"(3,1)=";cin>>a7;
cout<<"(3,2)=";cin>>a8;
cout<<"(3,3)=";cin>>a9;
cout << "\nMatriks A = \n";
cout<<"\t\t"<<a1<<"\t"<<a2<<"\t"<<a3<<"\n"<<"\t\t"<<a4<<"\t"<<a5<<"\t"<<a6<<"\n"<<"\t\t"<<a7<<"\t"<<a8<<"\t"<<a9<<"\n\n";
cout << "Masukkan Matrix B = \n";
cout<<"(1,1)=";cin>>b1;
cout<<"(1,2)=";cin>>b2;
cout<<"(1,3)=";cin>>b3;
cout<<"(2,1)=";cin>>b4;
cout<<"(2,2)=";cin>>b5;
cout<<"(2,3)=";cin>>b6;
cout<<"(3,1)=";cin>>b7;
cout<<"(3,2)=";cin>>b8;
cout<<"(3,3)=";cin>>b9;
cout << "\nMatriks B = \n";
cout<<"\t\t"<<b1<<"\t"<<b2<<"\t"<<b3<<"\n"<<"\t\t"<<b4<<"\t"<<b5<<"\t"<<b6<<"\n"<<"\t\t"<<b7<<"\t"<<b8<<"\t"<<b9<<"\n\n";
cout<<"matrix (A+B)= \n";
cout<<"\t\t"<<a1+b1<<"\t"<<a2+b2<<"\t"<<a3+b3<<"\n"<<"\t\t"<<a4+b4<<"\t"<<a5+b5<<"\t"<<a6+b6<<"\n"<<"\t\t"<<a7+b7<<"\t"<<a8+b8<<"\t"<<a9+b9<<"\n\n";
cout<<"matrix (A-B)= \n";
cout<<"\t\t"<<a1-b1<<"\t"<<a2-b2<<"\t"<<a3-b3<<"\n"<<"\t\t"<<a4-b4<<"\t"<<a5-b5<<"\t"<<a6-b6<<"\n"<<"\t\t"<<a7-b7<<"\t"<<a8-b8<<"\t"<<a9-b9<<"\n\n";
cout<<"matrix (B-A)= \n";
cout<<"\t\t"<<b1-a1<<"\t"<<b2-a2<<"\t"<<b3-a3<<"\n"<<"\t\t"<<b4-a4<<"\t"<<b5-a5<<"\t"<<b6-a6<<"\n"<<"\t\t"<<b7-a7<<"\t"<<b8-a8<<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<b9<<"\t"<<"|"<<"\t"<<b7<<"\t"<<a8<<"\n\n";
cout<<"\t"<<"("<<b1<<"*"<<b5<<"*"<<b9<<"+"<<b2<<"*"<<b6<<"*"<<b7<<"+"<<b3<<"*"<<b4<<"*"<<b8<<")"<<"-"<<"("<<b2<<"*"<<b4<<"*"<<b9<<"+"<<b1<<"*"<<b6<<"*"<<b8<<"+"<<b3<<"*"<<b5<<"*"<<b7<<")"<<"\n"<<"\t\t"<<b1*b5*b9+b2*b6*b7+b3*b4*b8<<" - "<<b2*b4*b9+b1*b6*b8+b3*b5*b7<<" = "<<(b1*b5*b9+b2*b6*b7+b3*b4*b8)-(b2*b4*b9+b1*b6*b8+b3*b5*b7)<<"\n\n";
cout<<"Tr (A)=";
cout<<"\t\t"<<"("<<a1<<"+"<<a5<<"+"<<a9<<")"<<" = "<<a1+a5+a9<<"\n\n";
cout<<"Tr (B)=";
cout<<"\t\t"<<"("<<b1<<"+"<<b5<<"+"<<b9<<")"<<" = "<<b1+b5+b9<<"\n\n";
break;
cout <<"\n";
cout<<"\n===========================================\n ";
}
back:
cout << "Apakah mau mengulangi (Y/T)?";cin>>tombol;cout << endl;
if (tombol == 'Y' || tombol == 'y'){goto menu;}
else if (tombol =='T' || tombol == 't') {exit;}
else {goto back;}
}
ini adalah hasil compile:
0 komentar:
Posting Komentar