From fcf38e62e8160f2c9901bdfd33760afed28beb8d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 22 Feb 2026 19:18:46 +0200 Subject: feat(Week01): Add solutions --- Week01/Exercise01/matrix.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Week01/Exercise01/matrix.cpp (limited to 'Week01/Exercise01/matrix.cpp') diff --git a/Week01/Exercise01/matrix.cpp b/Week01/Exercise01/matrix.cpp new file mode 100644 index 0000000..c8bdff2 --- /dev/null +++ b/Week01/Exercise01/matrix.cpp @@ -0,0 +1,28 @@ +#include "matrix.h" + +int** newMatrix(unsigned rows, unsigned cols) { + int** mat = new int*[rows]; + + for (unsigned i = 0; i < rows; ++i) + mat[i] = new int[cols]; + + return mat; +} + +void deleteMatrix(int**& matrix, unsigned rows) { + for (unsigned i = 0; i < rows; ++i) + delete[] matrix[i]; + delete[] matrix; + + matrix = nullptr; +} + +int sumMatrix(const int** matrix, unsigned rows, unsigned cols) { + int sum = 0; + + for (unsigned row = 0; row < rows; ++row) + for (unsigned col = 0; col < cols; ++col) + sum += matrix[row][col]; + + return sum; +} -- cgit v1.3.1-23-gd82d