-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path66.cpp
More file actions
35 lines (29 loc) · 879 Bytes
/
66.cpp
File metadata and controls
35 lines (29 loc) · 879 Bytes
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
34
35
#include <iostream>
using namespace std;
const int MAX = 100;
int main() {
int matrix[MAX][MAX], rows, cols;
// Input the number of rows and columns
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
// Input the elements of the matrix
cout << "Enter the elements of the matrix:\n";
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
cin >> matrix[i][j];
}
}
// Find the largest element in each row
for(int i = 0; i < rows; i++) {
int maxElement = matrix[i][0];
for(int j = 1; j < cols; j++) {
if(matrix[i][j] > maxElement) {
maxElement = matrix[i][j];
}
}
cout << "The largest element in row " << i+1 << " is: " << maxElement << endl;
}
return 0;
}