Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program to compute the multiplication of two n × m matrices.
- #include<stdio.h>
- int main()
- {
- int a1[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
- int a2[3][3] = {{1,4,7}, {2,5,8}, {3,6,9}};
- int mat[3][3] = {0};
- int sum = 0;
- // Computing
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- {
- for (int k = 0; k < 3; ++k)
- {
- sum += a1[i][k] * a2[k][j];
- }
- mat[i][j] = sum;
- sum = 0;
- }
- }
- // Print multiplication of two n × m matrices
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 3; ++j)
- printf("%d ", mat[i][j]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment