Answer to Question #288852 in C for nish

Question #288852

Mr. Umar while performing some operations comes to know that the image that he wants can be obtained by multiplying the original image with the pattern. Help Mr. Umar to get the resultant image by performing the matrix multiplication.


1
Expert's answer
2022-01-19T10:35:29-0500
#include <iostream>

using namespace std;

#define R1 4            
#define C1 4           
#define R2 4           
#define C2 4           


void mulMat(int mat1[][C1], int mat2[][C2]) {
    int rslt[R1][C2];

    cout << "Multiplication of given two matrices is:\n" << endl;

    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];
            }


            cout << rslt[i][j] << "\t";
        }


        cout << endl;
    }
}

int main() {
 
    int mat1[R1][C1] = {
            {1, 1, 1, 1},
            {2, 2, 2, 2},
            {3, 3, 3, 3},
            {4, 4, 4, 4}
    };
    int mat2[R2][C2] = {
            {1, 1, 1, 1},
            {2, 2, 2, 2},
            {3, 3, 3, 3},
            {4, 4, 4, 4}
    };

    if (C1 != R2) {
        cout << "The number of columns in Matrix-1  must be equal to the number of rows in "
            "Matrix-2" << endl;
        cout << "Please update MACROs according to your array dimension in #define section"
            << endl;


        exit(EXIT_FAILURE);
    }

    mulMat(mat1, mat2);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS