Advertisement
bayu1st

Untitled

Nov 25th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std ;
  5.  
  6. main(){
  7.     system ("color 0A");
  8.     int MA[3][3],MB[3][3],MC[3][3],pil;
  9.     do {
  10.         system("cls");
  11.         cout << "      PROGRAM PENGHITUNG MATRIKS ORDO 3X3"<<endl;
  12.         cout << "      ----------------------------------"<<endl;
  13.         cout << "1. Program Penjumlahan Matriks"<<endl<<"2. Program Perkalian Matriks"<<endl;
  14.         cout << "Silahkan Masukan Pilihan Anda : "; cin >> pil;
  15.         system("cls");
  16.         switch (pil){
  17.             case 1 : {
  18.                 cout<<" Program Penjumlahan Matriks" << endl;
  19.                 cout<<" ===========================" <<endl<<endl;
  20.                 cout<<"Matriks A"<<endl;
  21.    
  22.                 for(int a=0; a<3; a++){
  23.                     for(int b=0; b<3; b++){
  24.                         cout << "Masukan Matriks A baris ke "<<(a+1)<<  " kolom ke "<< (b+1) <<" : ";cin>>MA[a][b];
  25.                     }
  26.                 }
  27.                 cout<<endl;
  28.        
  29.                 cout<<"MATRIKS B "<< endl;
  30.        
  31.                 for(int a=0; a<3; a++){
  32.                     for(int b=0; b<3; b++){
  33.                         cout << "Masukan Matriks A baris ke "<<(a+1)<<  " kolom ke "<< (b+1) <<" : ";cin>>MB[a][b];
  34.                     }
  35.                 }
  36.                 cout<<endl;
  37.                 cout<<"------------------------------------------------------------------\n"<<endl;
  38.                 cout << "\nMATRIKS A"<<endl;
  39.                 for(int a=0; a<3; a++){
  40.                     for(int b=0; b<3; b++){
  41.                         cout << MA[a][b]<<"    ";
  42.                     }  
  43.                 cout << endl;
  44.                 }
  45.                 cout << "\nMATRIKS A"<<endl;
  46.                 for(int a=0; a<3; a++){
  47.                     for(int b=0; b<3; b++){
  48.                         cout << MB[a][b]<<"    ";
  49.                     }
  50.                 cout << endl;
  51.                 }
  52.         //Proses
  53.                 for(int a=0; a<3; a++){
  54.                     for(int b=0; b<3; b++){
  55.                     MC[a][b]=MA[a][b]+MB[a][b];
  56.                     }
  57.                 }
  58.         //output
  59.    
  60.                 cout<<"-------------------------------------------------------------------+"<<endl;
  61.                 for(int a=0; a<3; a++){
  62.                     for(int b=0; b<3; b++){
  63.                         cout<<MC[a][b]<<"    ";
  64.                     }
  65.                 cout << endl;
  66.                 }
  67.        
  68.            
  69.                 break;
  70.         }
  71.             case 2 : {
  72.                 cout<<" Program Penjumlahan Matriks" << endl;
  73.                 cout<<" ===========================" <<endl<<endl;
  74.                 cout << "MATRIKS A"<<endl;
  75.         //input
  76.                 for (int i = 0; i < 3;i++){
  77.                     for (int j = 0;j< 3 ;j++){
  78.                         cout << "Masukan Matriks A baris ke "<<(i+1)<<  " kolom ke "<< (j+1) <<" : "; cin >> MA[i][j];
  79.                     }
  80.                 }
  81.                 cout << "MATRIKS B"<<endl;
  82.                 for (int i = 0; i < 3;i++){
  83.                     for (int j = 0;j< 3 ;j++){
  84.                         cout << "Masukan Matriks A baris ke "<<(i+1)<<  " kolom ke "<< (j+1) <<" : "; cin >> MB[i][j];
  85.                     }
  86.                 }
  87.         //process
  88.        
  89.         //tampil
  90.                 cout << "-------------------------------------------------------------------------------"<<endl ;
  91.                 cout << "\nMatriks A" << endl;
  92.                 for (int i = 0; i < 3;i++){
  93.                     for (int j = 0;j< 3 ;j++){
  94.                         cout << MA[i][j]<< "  ";
  95.                     }
  96.                 cout << endl;
  97.                 }
  98.                 cout << "\nMatriks B" << endl;
  99.                 for (int i = 0; i < 3;i++){
  100.                     for (int j = 0;j< 3 ;j++){
  101.                     cout << MB[i][j]<<"  ";
  102.                     }
  103.                 cout << endl;
  104.                 }
  105.                 cout << "------------------------------------------------------------------------------- X"<<endl ;
  106.         //rumus perkalian matriks
  107.                 for (int i=0;i<3;i++){
  108.                     for (int j=0;j<3;j++){
  109.                         MC[i][j]=0;
  110.                         for (int k=0;k< 3;k++){
  111.                             MC[i][j]+= MA[i][k]*MB[k][j];
  112.                         }
  113.                     }
  114.                 }
  115.     //output matrik hasil perkalian
  116.                 cout<<endl;
  117.                 for(int i=0;i<3;i++){
  118.                     for(int j=0;j<3;j++){
  119.                         cout<< MA[i][j]<< "  ";
  120.                     }
  121.                 cout<<endl;
  122.                 }
  123.                 break;
  124.             }
  125.             default : {
  126.                 cout << "Input Anda Tidak Valid .!!!\a"<<endl<<"Silahkan di ulang";
  127.                 break;
  128.             }
  129.         }
  130.     }
  131.     while (pil == 3);
  132.  
  133.     cin.get();
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement