Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise05.cpp
blob: 897ed4b6d037240231ee3ea2434b389eca1fd886 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
}