Info2-Aufgabe2/matrix.c
2025-11-14 21:15:48 +01:00

64 lines
1.4 KiB
C

#include <stdlib.h>
#include <string.h>
#include "matrix.h"
// TODO Matrix-Funktionen implementieren
Matrix createMatrix(unsigned int rows, unsigned int cols)
{
}
void clearMatrix(Matrix *matrix)
{
}
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
matrix.data[rowIdx][colIdx] = value;
}
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
MatrixType value = matrix.data[rowIdx][colIdx];
return value;
}
Matrix add(const Matrix matrix1, const Matrix matrix2)
{
Matrix invalidResult = {0};
if (
matrix1.rows == 0 || matrix1.cols == 0 || matrix2.rows == 0 || matrix2.cols == 0 ||
matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols ||
matrix1.data == NULL || matrix2.data == NULL
)
{
return invalidResult;
}
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
if (result.data == NULL)
return invalidResult;
for (unsigned int row = 0; row < matrix1.rows; row++)
{
MatrixType *dstRow = result.data[row];
MatrixType *row1 = matrix1.data[row];
MatrixType *row2 = matrix2.data[row];
for (unsigned int col = 0; col < matrix1.cols; col++)
{
dstRow[col] = row1[col] + row2[col];
}
}
return result;
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
}