diff options
feat(Week10): Add solutions
1 files changed, 33 insertions, 0 deletions
| -rw-r--r-- | Week10/Exercise05.cpp | 33 |
diff --git a/Week10/Exercise05.cpp b/Week10/Exercise05.cpp new file mode 100644 index 0000000..897ed4b --- /dev/null +++ b/Week10/Exercise05.cpp @@ -0,0 +1,33 @@ +#include <iostream> + +int largest(int** mat, unsigned int rows, unsigned int cols) { + int max = mat[0][0]; + + for (unsigned int row = 0; row < rows; row++) + for (unsigned int col = 0; col < cols; col++) + if (mat[row][col] > max) + max = mat[row][col]; + + return max; +} + +int main() { + int rows, cols; + std::cin >> rows >> cols; + + int** mat = new int*[rows]; + for (unsigned int row = 0; row < rows; row++) { + mat[row] = new int[cols]; + + for (unsigned int col = 0; col < cols; col++) + std::cin >> mat[row][col]; + } + + std::cout << largest(mat, rows, cols) << std::endl; + + for (unsigned int row = 0; row < rows; row++) + delete[] mat[row]; + delete[] mat; + + return 0; +} |
