From eefb2829c150882e70609012ecb75aa20ac21e51 Mon Sep 17 00:00:00 2001 From: glockeel104125 Date: Thu, 12 Nov 2026 11:11:20 +0100 Subject: [PATCH] =?UTF-8?q?n=C3=A4chster=20Termin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Startcode/matrix.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 5bc0849..d1951b8 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -9,29 +9,72 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix m; m.rows = rows; m.cols = cols; + m.Memory = malloc(rows*cols*sizeof(MatrixType)) // + return m; } void clearMatrix(Matrix *matrix) { - + for (unsigned int i = 0; i < (*matrix).rows; i++) { + for (unsigned int j = 0; j < (*matrix).cols; j++) { + (*matrix).Memory[i * (*matrix).cols + j] = 0; + } + } } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if (rowIdx >= matrix.rows || colIdx >= matrix.cols) { + printf("Fehler: Index außerhalb der Matrix\n"); + return; + } + matrix.Memory[rowIdx * matrix.cols + colIdx] = value; } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if (rowIdx >= matrix.rows || colIdx >= matrix.cols) { + printf("Fehler: Index außerhalb der Matrix\n"); + return 0; + } + + return matrix.Memory[rowIdx * matrix.cols + colIdx]; } Matrix add(const Matrix matrix1, const Matrix matrix2) { + + //2 fälle 1. 2 matrizen exakt gleich groß, dann einfach jeden wert mit der selben pos addieren + // 2. 1 matrix beliebig groß und einen vektor, 1 spalte aber dafür rows gleich viele, dann einfach in jeder spalte einmal die row zahl vom vektor drauf addieren +if (matrix1.rows == matrix2.rows && matrix1.cols == matrix2.cols){ + +} + +ifelse(matrix1.cols == 1 || matrix2.cols == 1) +{ + + //sub fälle (1matrix vektor) (2matrix vektor) (beides vektoren) + + +} + +else{ + printf("Fehler: Matrizen können nicht miteinander addiert werden\n"); +} + + } Matrix multiply(const Matrix matrix1, const Matrix matrix2) { + if (matrix1.rows == matrix2.cols); + + + + + else{ + printf("Fehler: Matrizen können nicht miteinander multipliziert werden\n"); + } } \ No newline at end of file