How to input and multiply two matrix using pointer in C programming. ROW 3 #define COL 3 /. Function declarations./ void matrixInput(int.
- Related Questions & Answers
- Selected Reading
A matrix is a rectangular array of numbers that is arranged in the form of rows and columns.
An example of a matrix is as follows.
A 3*4 matrix has 3 rows and 4 columns as shown below.
A program that multiplies two matrices by passing the matrices to functions is as follows.
Example
Output
In the above program, the two matrices a and b are initialized in the main() function as follows.
The function MatrixMultiplication() is called with the values of a and b. This is seen below.
In the function MatrixMultiplication(), if the number of columns in the first matrix are not equal to the number of rows in the second matrix then multiplication cannot be performed. In this case an error message is printed. It is given as follows.
After this, the product[][] matrix is initialized to 0. Then a nested for loop is used to find the product of the 2 matrices a and b. This is demonstrated in the below code snippet.
After the product is obtained, it is printed. This is shown as follows.