INPUT FORMAT:
The input consists of (m*n+2) integers.
The first integer corresponds to m, the number of rows in the matrix and the second integer corresponds to n, the number of columns in the matrix.
The remaining integers correspond to the elements in the matrix.
The elements are read in row-wise order, the first row first, then the second row and so on.
Assume that the maximum value of m and n is 10.
OUTPUT FORMAT:
Refer to the sample output for details.
SAMPLE INPUT & OUTPUT:
3
2
4 5
6 9
0 3
The maximum element is 9
SOLUTION:
#include<iostream>
using namespace std;
int main()
{
int r, c;
cin>>r>>c;
int a[r][c];
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
cin>>a[i][j];
}
}
int temp = a[0][0];
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(temp < a[i][j])
temp = a[i][j];
}
}
cout<<"The maximum element is "<<temp;
}
No comments:
Post a Comment