Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define R1 2 // number of rows in Matrix-1
- #define C1 2 // number of columns in Matrix-1
- #define R2 2 // number of rows in Matrix-2
- #define C2 3 // number of columns in Matrix-2
- void mulMat(int mat1[][C1], int mat2[][C2])
- {
- int rslt[R1][C2];
- for (int i = 0; i < R1; i++) {
- for (int j = 0; j < C2; j++) {
- rslt[i][j] = 0;
- for (int k = 0; k < R2; k++) {
- rslt[i][j] += mat1[i][k] * mat2[k][j];
- }
- }
- }
- }
- int main()
- {
- // R1 = 4, C1 = 4 and R2 = 4, C2 = 4
- int mat1[R1][C1] = { { 1, 1 }, { 2, 2 } };
- int mat2[R2][C2] = { { 1, 1, 1 }, { 2, 2, 2 } };
- if (C1 != R2) {
- exit(EXIT_FAILURE);
- }
- mulMat(mat1, mat2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement