Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Matrix{
- int nrows;
- int ncols;
- int** matrix;
- };
- struct Matrix init_matrix(int r, int c)
- {
- struct Matrix mat;
- mat.nrows = r;
- mat.ncols = c;
- mat.matrix = calloc(r, sizeof(int *));
- for(int i = 0; i < r; ++i)
- {
- *(mat.matrix+i) = calloc(c, sizeof(int));
- }
- return mat;
- }
- void free_matrix(struct Matrix mat)
- {
- int top = mat.nrows;
- for(int i = 0; i < top; ++i)
- {
- free(mat.matrix[i]);
- }
- free(mat.matrix);
- }
- 3 3
- 1 2 3
- 4 5 6
- 7 8 9
- int main(int argc, char *argv[])
- {
- struct Matrix mat1 = create_matrix();
- char operation = get_operation();
- struct Matrix mat2 = create_matrix();
- struct Matrix result = compute(mat1,mat2, operation);
- return 0;
- }
Add Comment
Please, Sign In to add comment