Page 327 - Computer science 868 Class 12
P. 327

32              for (int i = 0; i < row2; i++)
                   33              {

                   34                  for (int j = 0; j < col2; j++)
                   35                      b[i][j] = s.nextInt();
                   36              }

                   37              System.out.println("\nMatrix multiplication is : ");

                   38              for (int i = 0; i < row1; i++)
                   39              {
                   40                  for (int j = 0; j < col2; j++)

                   41                  {
                   42

                   43                      c[i][j] = 0;
                   44

                   45                      for (int k = 0; k < col1; k++)
                   46                      {

                   47                          c[i][j] += a[i][k] * b[k][j];
                   48                      }

                   49                  }
                   50              }

                   51              System.out.println("The product is:");
                   52              for (int i = 0; i < row1; i++)

                   53              {
                   54                  for (int j = 0; j < col2; j++)

                   55                  {
                   56                      System.out.print(c[i][j] + " ");

                   57                  }
                   58                  System.out.println();

                   59              }
                   60          }
                   61      }


                 The output of the preceding program is as follows:
                 Enter the number of rows in the first matrix: 2
                 Enter the number of columns in the first matrix: 3
                 Enter the number of rows in the second matrix: 3
                 Enter the number of columns in the second matrix: 2



                                                                                                                       325
                                                                                                              Arrays   325
   322   323   324   325   326   327   328   329   330   331   332