Compare commits
2 Commits
6179dca96a
...
2142433257
| Author | SHA1 | Date | |
|---|---|---|---|
| 2142433257 | |||
| 2dbcc110fc |
30
matrix.c
30
matrix.c
@ -50,6 +50,36 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
|||||||
|
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
//Überprüfen, ob die Matrizen die gleichen Dimensionen haben
|
||||||
|
//wenn nicht muss die matrix "rows/cols=0 und buffer = NULL" leer zurückgegeben werden
|
||||||
|
|
||||||
|
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
||||||
|
{
|
||||||
|
Matrix result;
|
||||||
|
result.rows = 0;
|
||||||
|
result.cols = 0;
|
||||||
|
result.buffer = NULL;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Matrix result ist die neue Matrix für das Ergebnis
|
||||||
|
Matrix result;
|
||||||
|
result.rows = matrix1.rows;
|
||||||
|
result.cols = matrix1.cols;
|
||||||
|
|
||||||
|
|
||||||
|
//Addition der beiden Matrizen
|
||||||
|
for (int i = 0; i < result.rows * result.cols; i++)
|
||||||
|
{
|
||||||
|
result.buffer[i] = matrix1.buffer[i] + matrix2.buffer[i];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user