Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std ;
- main(){
- system ("color 0A");
- int MA[3][3],MB[3][3],MC[3][3],pil;
- do {
- system("cls");
- cout << " PROGRAM PENGHITUNG MATRIKS ORDO 3X3"<<endl;
- cout << " ----------------------------------"<<endl;
- cout << "1. Program Penjumlahan Matriks"<<endl<<"2. Program Perkalian Matriks"<<endl;
- cout << "Silahkan Masukan Pilihan Anda : "; cin >> pil;
- system("cls");
- switch (pil){
- case 1 : {
- cout<<" Program Penjumlahan Matriks" << endl;
- cout<<" ===========================" <<endl<<endl;
- cout<<"Matriks A"<<endl;
- for(int a=0; a<3; a++){
- for(int b=0; b<3; b++){
- cout << "Masukan Matriks A baris ke "<<(a+1)<< " kolom ke "<< (b+1) <<" : ";cin>>MA[a][b];
- }
- }
- cout<<endl;
- cout<<"MATRIKS B "<< endl;
- for(int a=0; a<3; a++){
- for(int b=0; b<3; b++){
- cout << "Masukan Matriks A baris ke "<<(a+1)<< " kolom ke "<< (b+1) <<" : ";cin>>MB[a][b];
- }
- }
- cout<<endl;
- cout<<"------------------------------------------------------------------\n"<<endl;
- cout << "\nMATRIKS A"<<endl;
- for(int a=0; a<3; a++){
- for(int b=0; b<3; b++){
- cout << MA[a][b]<<" ";
- }
- cout << endl;
- }
- cout << "\nMATRIKS A"<<endl;
- for(int a=0; a<3; a++){
- for(int b=0; b<3; b++){
- cout << MB[a][b]<<" ";
- }
- cout << endl;
- }
- //Proses
- for(int a=0; a<3; a++){
- for(int b=0; b<3; b++){
- MC[a][b]=MA[a][b]+MB[a][b];
- }
- }
- //output
- cout<<"-------------------------------------------------------------------+"<<endl;
- for(int a=0; a<3; a++){
- for(int b=0; b<3; b++){
- cout<<MC[a][b]<<" ";
- }
- cout << endl;
- }
- break;
- }
- case 2 : {
- cout<<" Program Penjumlahan Matriks" << endl;
- cout<<" ===========================" <<endl<<endl;
- cout << "MATRIKS A"<<endl;
- //input
- for (int i = 0; i < 3;i++){
- for (int j = 0;j< 3 ;j++){
- cout << "Masukan Matriks A baris ke "<<(i+1)<< " kolom ke "<< (j+1) <<" : "; cin >> MA[i][j];
- }
- }
- cout << "MATRIKS B"<<endl;
- for (int i = 0; i < 3;i++){
- for (int j = 0;j< 3 ;j++){
- cout << "Masukan Matriks A baris ke "<<(i+1)<< " kolom ke "<< (j+1) <<" : "; cin >> MB[i][j];
- }
- }
- //process
- //tampil
- cout << "-------------------------------------------------------------------------------"<<endl ;
- cout << "\nMatriks A" << endl;
- for (int i = 0; i < 3;i++){
- for (int j = 0;j< 3 ;j++){
- cout << MA[i][j]<< " ";
- }
- cout << endl;
- }
- cout << "\nMatriks B" << endl;
- for (int i = 0; i < 3;i++){
- for (int j = 0;j< 3 ;j++){
- cout << MB[i][j]<<" ";
- }
- cout << endl;
- }
- cout << "------------------------------------------------------------------------------- X"<<endl ;
- //rumus perkalian matriks
- for (int i=0;i<3;i++){
- for (int j=0;j<3;j++){
- MC[i][j]=0;
- for (int k=0;k< 3;k++){
- MC[i][j]+= MA[i][k]*MB[k][j];
- }
- }
- }
- //output matrik hasil perkalian
- cout<<endl;
- for(int i=0;i<3;i++){
- for(int j=0;j<3;j++){
- cout<< MA[i][j]<< " ";
- }
- cout<<endl;
- }
- break;
- }
- default : {
- cout << "Input Anda Tidak Valid .!!!\a"<<endl<<"Silahkan di ulang";
- break;
- }
- }
- }
- while (pil == 3);
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement