document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <iomanip.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int A[1000][1000],B[1000][1000],C[1000][1000],i,j,k, barisa, koloma, barisb, kolomb, barisc, kolomc, loop;
  9. void hitung();
  10. void matrika();
  11. void matrikb();
  12. void cek();
  13. void ulang();
  14.  
  15. int main()
  16. {
  17.     do
  18.     {
  19.         matrika();
  20.         matrikb();
  21.         ulang();
  22.     }while (loop!=0);
  23. }
  24.  
  25. void matrika()
  26. {
  27.     cout<<"masukkan ordo matriks A :"<<endl;
  28.     cout<<"jumlah baris : ";
  29.     cin>>barisa;
  30.     cout<<"jumlah kolom : ";
  31.     cin>>koloma;
  32.  
  33.     //masukkan matrix A
  34.     cout<<"Silahkan input matrik A : \\n";
  35.     for(i=0;i<barisa;i++)
  36.     {
  37.         for(j=0;j<koloma;j++)
  38.         {
  39.             cout<<"Elemen ke "<<(i+1)<<","<<(j+1)<<" : ";
  40.             cin>>A[i][j];
  41.         }
  42.     }
  43.  
  44.     //cetak matrix A
  45.     cout<<"\\nMatrik A : \\n";
  46.     for(i=0;i<barisa;i++)
  47.     {
  48.         for(j=0;j<koloma;j++)
  49.         {
  50.             cout<<setw(4)<<A[i][j];
  51.         }
  52.         cout<<endl;
  53.     }
  54.     cout<<endl;
  55. }
  56.  
  57. void matrikb()
  58. {
  59.      barisb = koloma;
  60.     //masukkan matriks B
  61.     cout<<"masukkan ordo matriks B :"<<endl;
  62.     cout<<"jumlah baris : "<<barisb;
  63.     cout<<"\\njumlah kolom : ";
  64.     cin>>kolomb;
  65.  
  66.     cout<<"Silahkan input matrik B : \\n";
  67.     for(i=0;i<barisb;i++)
  68.     {
  69.         for(j=0;j<kolomb;j++)
  70.         {
  71.         cout<<"Elemen ke "<<(i+1)<<","<<(j+1)<<" : ";
  72.         cin>>B[i][j];
  73.         }
  74.     }
  75.  
  76.     //cetak matrix B
  77.     cout<<"\\nMatrik B : \\n";
  78.     for(i=0;i<barisb;i++)
  79.     {
  80.         for(j=0;j<kolomb;j++)
  81.         {
  82.             cout<<setw(4)<<B[i][j];
  83.         }
  84.         cout<<endl;
  85.     }
  86. }
  87.  
  88. void hitung()
  89. {
  90.     //Operasi Perkalian
  91.     for (i=0;i<barisa;i++)
  92.     {
  93.         for (j=0;j<kolomb;j++)
  94.         {
  95.             C[i][j]=0;
  96.             for (k=0;k<barisb;k++)
  97.             {
  98.                 C[i][j]+= A[i][k]*B[k][j];
  99.             }
  100.         }
  101.     }
  102.  
  103.     //Menampilkan hasil
  104.  
  105.     cout<<"\\nMatrik C, Hasil : \\n";
  106.     for(i=0;i<barisa;i++)
  107.     {
  108.         for(j=0;j<kolomb;j++)
  109.         {
  110.             cout<<setw(4)<<C[i][j];
  111.         }
  112.         cout<<endl;
  113.     }
  114.     cout<<endl;
  115.     getche();
  116. }
  117.  
  118. void ulang()
  119. {
  120.     int status, l;
  121.     char pilih;
  122.     do
  123.     {
  124.         cout<<"anda ingin memakai program ini lagi (y/n)?";
  125.         cin>>pilih;
  126.         switch (pilih)
  127.         {
  128.             case \'Y\' : status=1; loop=1; l=0;  break;
  129.             case \'y\' : status=1; loop=1; l=0;  break;
  130.             case \'N\' : status=0; l=0; cout<<"exit"<<endl; getche(); exit(0); break;
  131.             case \'n\' : status=0; l=0; cout<<"exit"<<endl; getche(); exit(0); break;
  132.             default : cout<<"ketik y untuk ulangi program, n untuk tutup program (tidak case sensitif)"<<endl;
  133.         }
  134.     }while(l!=0);
  135. }
');