From abe4ecec657eece9b9436faa1ebd47419afbe64f Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Mon, 17 Nov 2025 10:04:39 +0100 Subject: [PATCH] Finished Matrix add Function Completing the Set Get Add Branch --- matrix.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index a60e891..efef3e9 100644 --- a/matrix.c +++ b/matrix.c @@ -46,7 +46,24 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co Matrix add(const Matrix matrix1, const Matrix matrix2) { - + Matrix MatrixErgebnis = createMatrix(matrix1.rows, matrix1.cols); //Creating Result Matrix + if(matrix1.cols != matrix2.cols || matrix1.rows != matrix2.rows){ + printf("Matrix dimensions do not match\n"); //Error Message if dimensions of Input Matrixes are not identical + MatrixErgebnis = clearMatrix(MatrixErgebnis); + return MatrixErgebnis; + } + else{ + + for (unsigned int i = 0; i < matrix1.rows; i++){ + for (unsigned int j = 0; j < matrix1.cols; j++){ + //Adding Matrix Elements of same row and col index together and store in new Matrix + MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j]; + + } + } + + } +return MatrixErgebnis; } Matrix multiply(const Matrix matrix1, const Matrix matrix2)