diff --git a/matrix.c b/matrix.c index d24b836..a47ec06 100644 --- a/matrix.c +++ b/matrix.c @@ -5,11 +5,11 @@ // TODO Matrix-Funktionen implementieren -typedef struct Matrix { +typedef struct Matrix{ unsigned int rows; unsigned int cols; MatrixType* buffer; -} Matrix; +}Matrix; Matrix createMatrix(unsigned int rows, unsigned int cols) @@ -31,10 +31,10 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned { if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix -} + } else{ matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix -} + } } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) @@ -47,8 +47,8 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable return value; + } } - } Matrix add(const Matrix matrix1, const Matrix matrix2) { @@ -65,16 +65,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) //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; + } + return MatrixErgebnis; } Matrix multiply(const Matrix matrix1, const Matrix matrix2) { - Matrix result; result.rows = matrix1.rows; result.cols = matrix2.cols; diff --git a/matrix.h b/matrix.h index a97ea5b..0771157 100644 --- a/matrix.h +++ b/matrix.h @@ -7,7 +7,11 @@ typedef float MatrixType; // TODO Matrixtyp definieren -typedef struct Matrix Matrix; +typedef struct Matrix{ + unsigned int rows; + unsigned int cols; + MatrixType* buffer; +}Matrix;