What do mathematicians sleep on? Matrices!!
A matrix is a rectangular arrangement of numbers into rows and columns. Each number in a matrix refers to a matrix element.
To perform matrix addition, you need to have two matrices of the same size. Then you can sum up the entries respectively.
Example:
We call the matrix above a
Now, given another
Since the size of
Implement the code to perform matrix addition.
#include <stdio.h>
void display_matrix(int matrix[][2], int num_row) {
for (int r = 0; r < num_row; r++) {
for (int c = 0; c < 2; c++) {
printf("\t%d", matrix[r][c]);
}
printf("\n");
}
}
int main() {
int matrix_A[3][2] = {
{0, 1},
{2, 3},
{4, 5}
};
int matrix_B[3][2] = {
{0, 1},
{2, 3},
{4, 5}
};
int result[3][2] = {0};
// your code starts here
// your code ends here
printf("A = \n");
display_matrix(matrix_A, 3);
printf("\nB = \n");
display_matrix(matrix_B, 3);
printf("\nA + B = \n");
display_matrix(result, 3);
return 0;
}