diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 0fe3484..37063d3 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -103,5 +103,29 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2) { - + if(matrix.cols !=matrix2.rows){ + Matrix result; + result.rows = 0; + result.cols = 0; + result.buffer = NULL; + + return result; + } + + Matrix resultMatrix = createMatrix(matrix1.rows, matrix2.cols); + if (resultMatrix.buffer == NULL) { + return resultMatrix; + } + + for (unsigned int i = 0; i < matrix1.rows; i++) { + for (unsigned int j = 0; j < matrix2.cols; j++) { + MatrixType sum = 0; + for (unsigned int k = 0; k < matrix1.cols; k++) { + sum += getMatrixAt(matrix1, i, j) * getMatrixAt(matrix2, k, j); + } + setMatrixAt(sum, resultMatrix, i, j); + + } + } + return resultMatrix; } \ No newline at end of file