Here's the C code that implements matrix addition and multiplication:
```c
#include <stdio.h>
#define SIZE 50
struct mat {
int row;
int col;
int value[SIZE][SIZE];
};
void scan_mat(struct mat *);
void print_mat(const struct mat *);
void add_mat(const struct mat *, const struct mat *, struct mat *);
void mul_mat(const struct mat *, const struct mat *, struct mat *);
int main(void) {
struct mat m1, m2, result;
char op;
scan_mat(&m1);
scanf(" %c", &op);
scan_mat(&m2);
switch (op) {
case '+':
add_mat(&m1, &m2, &result);
break;
case '*':
mul_mat(&m1, &m2, &result);
break;
}
print_mat(&result);
return 0;
}
void scan_mat(struct mat *m_p) {
scanf("%d %d", &m_p->row, &m_p->col);
for (int i = 0; i < m_p->row; ++i) {
for (int j = 0; j < m_p->col; ++j) {
scanf("%d", &m_p->value[i][j]);
}
}
}
void print_mat(const struct mat *m_p) {
for (int i = 0; i < m_p->row; ++i) {
for (int j = 0; j < m_p->col; ++j) {
printf("%d ", m_p->value[i][j]);
}
printf("\\");
}
}
void add_mat(const struct mat *m1_p, const struct mat *m2_p, struct mat *result_p) {
result_p->row = m1_p->row;
result_p->col = m1_p->col;
for (int i = 0; i < m1_p->row; ++i) {
for (int j = 0; j < m1_p->col; ++j) {
result_p->value[i][j] = m1_p->value[i][j] + m2_p->value[i][j];
}
}
}
void mul_mat(const struct mat *m1_p, const struct mat *m2_p, struct mat *result_p) {
result_p->row = m1_p->row;
result_p->col = m2_p->col;
for (int i = 0; i < m1_p->row; ++i) {
for (int j = 0; j < m2_p->col; ++j) {
result_p->value[i][j] = 0;
for (int k = 0; k < m1_p->col; ++k) {
result_p->value[i][j] += m1_p->value[i][k] * m2_p->value[k][j];
}
}
}
}
```
In this code, the functions `scan_mat`, `print_mat`, `add_mat`, and `mul_mat` are defined as described in the loader code.
The `scan_mat` function scans the row and column numbers of a matrix, and then scans the matrix elements.
The `print_mat` function prints the elements of a matrix.
The `add_mat` function adds two matrices element-wise and stores the result in the `result` matrix.
The `mul_mat` function multiplies two matrices using matrix multiplication rules and stores the result in the `result` matrix.
In the `main` function, the matrices `m1`, `m2`, and `result` are declared and scanned using the `scan_mat` function. The operation character is scanned, and based on the operation, either matrix addition or multiplication is performed using the respective functions. Finally, the result matrix is printed using the `print_mat` function.