Page 123 - Modul Algoritma dan Pemrograman Dasar HTML
P. 123

void Cetak(int Mat_A[][Klm], int &Brs, int &Klm);
                               void Jumlah(int Mat_a[][Klm], int Mat_B[][Klm], int
                               Mat_C[][Klm], int &Brs, int &Klm);
                               void Selisih(int Mat_A[Brs][Klm], int Mat_B[Brs][Klm],
                               int Mat_C[Brs][Klm], int &Brs, int &Klm);

                               main()
                               {
                                 int Brs1, Klm1, Brs2, Klm2;
                                 int Mat_A[Brs][Klm], Mat_B[Brs][Klm];
                                 int Mat_C[Brs][Klm], Mat_D[Brs][Klm];
                                 cout<<"Banyak Baris Matriks A = "; cin>>Brs1;
                                 cout<<"Banyak Kolom Matriks A = "; cin>>Klm1;
                                 cout<<"Banyak Baris Matriks B = "; cin>>Brs2;
                                 cout<<"Banyak Kolom Matriks B = "; cin>>Klm2;
                                 cout<<"Elemen Matriks A : \n";
                                 Baca(Mat_A, Brs1, Klm1);
                                 cout<<"\nElemen Matriks B : \n";
                                 Baca(Mat_B, Brs1, Klm1);
                                 cout<<"\nMatriks A : \n";
                                 Cetak(Mat_A, Brs1, Klm1);
                                 cout<<"\nMatriks B : \n";
                                 Cetak(Mat_B, Brs1, Klm1);
                                 if(Brs1==Brs2 && Klm1==Klm2)
                                 {
                                   Jumlah(Mat_A, Mat_B, Mat_C, Brs1, Klm1);
                                   Selisih(Mat_A, Mat_B, Mat_D, Brs1, Klm1);
                                   cout<<"\nMatriks C = A + B : \n";
                                   Cetak(Mat_C, Brs1, Klm1);
                                   cout<<"\nMatriks D = A - B : \n";
                                   Cetak(Mat_D, Brs1, Klm1);
                                 }
                                 else
                                   cout<<"Kedua Matriks tidak dapat dijumlah dan
                               dikurangkan..";
                                 getch();
                               }

                               void Cetak(int Mat_A[][Klm], int &Brs, int &Klm)
                               {
                                 int i, j;
                                 for(i=0;i<Brs;i++)
                                 {
                                   for(j=0;j<Klm;j++)
                                     cout<<setw(3)<<Mat_A[i][j];




                                                                                                    118
   118   119   120   121   122   123   124   125   126   127   128