addmatrix fertig Testdatei PASS

This commit is contained in:
Ben Skuppin 2025-11-17 13:27:23 +01:00
parent 7513db75b9
commit 7f797957aa

View File

@ -45,7 +45,50 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
Matrix add(const Matrix matrix1, const Matrix matrix2)
{
return matrix1;
int matrixResultCols;
if(matrix1.cols <= matrix2.cols){
matrixResultCols = matrix2.cols;
}
else{
matrixResultCols = matrix1.cols;
}
Matrix result = createMatrix(matrix1.rows, matrixResultCols);
if(matrix1.rows != matrix2.rows){
result.buffer = NULL;
result.rows = 0;
result.cols = 0;
return result;
}
if(matrix1.cols == matrix2.cols){
for(int i = 0; i < matrix1.rows; i++){
for(int j = 0; j < matrix1.cols; j++){
*(result.buffer + (matrix1.cols * i + j)) = *(matrix1.buffer + (matrix1.cols * i + j)) + *(matrix2.buffer + (matrix2.cols * i + j)) ;
}
}
}
if((matrix1.cols ==1 && matrix2.cols != 1)){
for(int i = 0; i < matrix2.rows; i++){
for(int j = 0; j < matrix2.cols; j++){
*(result.buffer + (result.cols * i + j)) = *(matrix2.buffer + (matrix2.cols * i + j)) + *(matrix1.buffer + i);
}
}
}
if((matrix2.cols == 1 && matrix1.cols != 1)){
for(int i = 0; i < matrix1.rows; i++){
for(int j = 0; j < matrix1.cols; j++){
*(result.buffer + (result.cols * i + j)) = *(matrix1.buffer + (matrix1.cols * i + j)) + *(matrix2.buffer + i);
}
}
}
return result;
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)