ibrahim_065

9.Write a program to compute the multiplication of two n × m matrices.

Aug 14th, 2020 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. // Write a program to compute the multiplication of two n × m matrices.
  2. #include<stdio.h>
  3. int main()
  4. {
  5.     int a1[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
  6.     int a2[3][3] = {{1,4,7}, {2,5,8}, {3,6,9}};
  7.     int mat[3][3] = {0};
  8.     int sum = 0;
  9.     // Computing
  10.     for (int i = 0; i < 3; ++i)
  11.     {
  12.         for (int j = 0; j < 3; ++j)
  13.         {
  14.             for (int k = 0; k < 3; ++k)
  15.             {
  16.                 sum += a1[i][k] * a2[k][j];
  17.             }
  18.             mat[i][j] = sum;
  19.             sum = 0;
  20.         }
  21.     }
  22.     // Print multiplication of two n × m matrices
  23.     for (int i = 0; i < 3; ++i)
  24.     {
  25.         for (int j = 0; j < 3; ++j)
  26.             printf("%d ", mat[i][j]);
  27.         printf("\n");
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment