[prev] [index] [next]

Exercise: Generic Matrix Library

Use dynamically allocated memory to implement the following library of Matrix operations:

typedef struct { int nrows, ncols; float **data; } Matrix;
int readMatrix(Matrix *);
void printMatrix(Matrix);
void copyMatrix(Matrix, Matrix);
void transMatrix(Matrix, Matrix);
void addMatrix(Matrix, Matrix, Matrix);
void mulMatrix(Matrix, Matrix, Matrix);

Notes:

  • readMatrix reads nrows, ncols, then the data
  • can only add matrices with equal rows and columns
  • can only multiply an n×m matrix with an m×p matrix