Advertisement
Guest User

asli

a guest
Mar 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. void jumlah(){
  8.     int i,j,x,y;
  9.     cout<< "Masukkan baris matriks A: ";
  10.     cin >>i;
  11.     cout<< "Masukkan kolom matriks A: ";
  12.     cin >>j; cout<<endl;
  13.  
  14.     int A[i][j];
  15.     for(x=0; x<i; x++){
  16.         for(y=0; y<j; y++){
  17.             cout<< "A[" << x << "][" << y << "]: ";
  18.             cin>>A[x][y];
  19.         }
  20.     } cout<<endl;
  21.     cout<< "Matriks A= " <<endl;
  22.     for(x=0; x<i; x++){
  23.         for(y=0; y<j; y++){
  24.             cout<< A[x][y] << " ";
  25.         }
  26.         cout<<endl;
  27.     }
  28.     cout<< "\nMasukkan baris matriks B: ";
  29.     cin >>i;
  30.     cout<< "Masukkan kolom matriks B: ";
  31.     cin >>j; cout<<endl;
  32.  
  33.     int B[i][j];
  34.     for(x=0; x<i; x++){
  35.         for(y=0; y<j; y++){
  36.             cout<< "B[" << x << "][" << y << "]: ";
  37.             cin>>B[x][y];
  38.         }
  39.     } cout<<endl;
  40.     cout<< "Matriks B= " <<endl;
  41.     for(x=0; x<i; x++){
  42.         for(y=0; y<j; y++){
  43.             cout<< B[x][y] << " ";
  44.         }
  45.         cout<<endl;
  46.     }
  47.     system("pause");
  48.     system("CLS");
  49.     cout<< "\nMatriks A + Matriks B= " <<endl;
  50.     int C[i][j];
  51.     for(x=0; x<i; x++){
  52.         for(y=0; y<j; y++){
  53.             C[x][y] = A[x][y] + B[x][y];
  54.             cout<< C[x][y] << " ";
  55.         }
  56.         cout<<endl;
  57.     }
  58. }
  59. void kurang(){
  60.     int i,j,x,y;
  61.     cout<< "Masukkan baris matriks A: ";
  62.     cin >>i;
  63.     cout<< "Masukkan kolom matriks A: ";
  64.     cin >>j; cout<<endl;
  65.  
  66.     int A[i][j];
  67.     for(x=0; x<i; x++){
  68.         for(y=0; y<j; y++){
  69.             cout<< "A[" << x << "][" << y << "]: ";
  70.             cin>>A[x][y];
  71.         }
  72.     } cout<<endl;
  73.     cout<< "Matriks A= " <<endl;
  74.     for(x=0; x<i; x++){
  75.         for(y=0; y<j; y++){
  76.             cout<< A[x][y] << " ";
  77.         }
  78.         cout<<endl;
  79.     }
  80.     cout<< "\nMasukkan baris matriks B: ";
  81.     cin >>i;
  82.     cout<< "Masukkan kolom matriks B: ";
  83.     cin >>j; cout<<endl;
  84.  
  85.     int B[i][j];
  86.     for(x=0; x<i; x++){
  87.         for(y=0; y<j; y++){
  88.             cout<< "B[" << x << "][" << y << "]: ";
  89.             cin>>B[x][y];
  90.         }
  91.     } cout<<endl;
  92.     cout<< "Matriks B= " <<endl;
  93.     for(x=0; x<i; x++){
  94.         for(y=0; y<j; y++){
  95.             cout<< B[x][y] << " ";
  96.         }
  97.         cout<<endl;
  98.     }
  99.     system("pause");
  100.     system("CLS");
  101.     cout<< "\nMatriks A - Matriks B= " <<endl;
  102.     int C[i][j];
  103.     for(x=0; x<i; x++){
  104.         for(y=0; y<j; y++){
  105.             C[x][y] = A[x][y] - B[x][y];
  106.             cout<< C[x][y] << " ";
  107.         }
  108.         cout<<endl;
  109.     }
  110. }
  111. void kali(){
  112.     int i,j,k,temp;
  113.     int x,y,z;
  114.  
  115.     cout<< "Masukkan kolom matriks A: ";
  116.     cin >>i;
  117.     cout<< "Masukkan baris matriks A: ";
  118.     cin >>j; cout<<endl;
  119.  
  120.     int A[i][j];
  121.     for(x=0; x<i; x++){
  122.         for(y=0; y<j; y++){
  123.             cout<< "A[" << x << "][" << y << "]: ";
  124.             cin>>A[x][y];
  125.         }
  126.     } cout<<endl;
  127.     cout<< "Matriks A= " <<endl;
  128.     for(x=0; x<i; x++){
  129.         for(y=0; y<j; y++){
  130.             cout<< A[x][y] << " ";
  131.         }
  132.         cout<<endl;
  133.     }
  134.     cout<< "\nMasukkan kolom matriks B: ";
  135.     cin >>j;
  136.     cout<< "Masukkan baris matriks B: ";
  137.     cin >>k; cout<<endl;
  138.  
  139.     int B[j][k];
  140.     for(y=0; y<j; y++){
  141.         for(z=0; z<k; z++){
  142.             cout<< "B[" << y << "][" << z << "]: ";
  143.             cin>>B[y][z];
  144.         }
  145.     } cout<<endl;
  146.     cout<< "Matriks B= " <<endl;
  147.     for(y=0; y<j; y++){
  148.         for(z=0; z<k; z++){
  149.             cout<< B[y][z] << " ";
  150.         }
  151.         cout<<endl;
  152.     }
  153.     system("pause");
  154.     system("CLS");
  155.     int C[i][k];
  156.     cout<< "Matriks A x Matriks B= " <<endl;
  157.     for(x=0; x<i; x++){
  158.         for(y=0; y<j; y++){
  159.  
  160.             C[x][y] = 0;
  161.  
  162.             for(z=0; z<k; z++){
  163.             temp = A[x][z]*B[z][y];
  164.             C[x][y] += temp;
  165.             }
  166.         }
  167.         cout<<endl;
  168.     }
  169.  
  170.     cout<< "Matriks C= " <<endl;
  171.     for(y=0; y<j; y++){
  172.         for(z=0; z<k; z++){
  173.             cout<< C[y][z] << " ";
  174.         }
  175.         cout<<endl;
  176.     }
  177. }
  178.  
  179. int main()
  180. {
  181.     int pilihan;
  182.  
  183.     menu:
  184.     cout<< "\t\t\t#==============================#" <<endl;
  185.     cout<< "\t\t\t#******** MENU MATRIKS ********#" <<endl;
  186.     cout<< "\t\t\t#==============================#" <<endl;
  187.     cout<< "\t\t\t# 1. PENJUMLAHAN               #" <<endl;
  188.     cout<< "\t\t\t# 2. PENGURANGAN               #" <<endl;
  189.     cout<< "\t\t\t# 3. PERKALIAN                 #" <<endl;
  190.     cout<< "\t\t\t# 4. KELUAR                    #" <<endl;
  191.     cout<< "\t\t\t#==============================#" <<endl;
  192.     cout<< "\t\t\t Masukkan pilihan: ";
  193.     cin>>pilihan;
  194.  
  195.     system("CLS");
  196.     switch(pilihan){
  197.     case 1: jumlah(); break;
  198.     case 2: kurang(); break;
  199.     case 3: kali(); break;
  200.     case 4: exit(0);
  201.     default:
  202.         cout<<"Kode yang anda masukkan salah :(";
  203.     }
  204.     system("pause");
  205.     system("CLS");
  206.     goto menu;
  207.     getch();
  208.  
  209.     return 0;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement