Question: Write a C++ program for matrix multiplication. Ask the user the number of rows and columns for the first matrix. The number of rows for
Write a C++ program for matrix multiplication.
Ask the user the number of rows and columns for the first matrix. The number of rows for the 2nd matrix should be the number of columns for the 1st matrix. Columns for the 2nd matrix is again a user required field.
Once you have the dimensions, ask the user to enter the elements of the matrices term by term.
Make sure to use vector
Once you have the 2 matrices, your task is to perform a matrix multiplication of the two matrices and store the result in a third matrix.
Required Functions
A function that asks the user to input the terms of the matrix. This function should also initialize your matrix to its correct values and return it. The parameters passed to this should be the number of rows and columns. Since you need to enter two matrices, this will be called twice.
One function that takes in the two initialized matrices and returns a third matrix. This is the function where you perform the multiplication.
A separate function to print a matrix. Using this function, print the original two matrices and then print the result matrix.
EX: if the input is:
Please specify the total row of your first matrix:
2
Please specify the total column of your first matrix:
2
Please specify the element of 0 row 0 col:
10
Please specify the element of 0 row 1 col:
-12
Please specify the element of 1 row 0 col:
55
Please specify the element of 1 row 1 col:
74
Please specify the total row of your second matrix:
2
Please specify the total column of your second matrix:
2
Please specify the element of 0 row 0 col:
-1
Please specify the element of 0 row 1 col:
0
Please specify the element of 1 row 0 col:
10
Please specify the element of 1 row 1 col:
20
the output is:
The input matrix A is:
10 -12
55 74
The input matrix B is:
-1 0
10 20
The final matrix is:
-130 -240
685 1480
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
