Guest User

Untitled

a guest
Nov 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. struct Matrix{
  2. int nrows;
  3. int ncols;
  4. int** matrix;
  5. };
  6.  
  7. struct Matrix init_matrix(int r, int c)
  8. {
  9. struct Matrix mat;
  10. mat.nrows = r;
  11. mat.ncols = c;
  12. mat.matrix = calloc(r, sizeof(int *));
  13. for(int i = 0; i < r; ++i)
  14. {
  15. *(mat.matrix+i) = calloc(c, sizeof(int));
  16. }
  17.  
  18. return mat;
  19. }
  20.  
  21. void free_matrix(struct Matrix mat)
  22. {
  23. int top = mat.nrows;
  24. for(int i = 0; i < top; ++i)
  25. {
  26. free(mat.matrix[i]);
  27. }
  28. free(mat.matrix);
  29. }
  30.  
  31. 3 3
  32. 1 2 3
  33. 4 5 6
  34. 7 8 9
  35.  
  36. int main(int argc, char *argv[])
  37. {
  38. struct Matrix mat1 = create_matrix();
  39. char operation = get_operation();
  40. struct Matrix mat2 = create_matrix();
  41. struct Matrix result = compute(mat1,mat2, operation);
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment