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 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:
3
2
4 5
6 9
0 3
SAMPLE OUTPUT:
5
9
3
SOLUTION:
#include<iostream>
using namespace std;
int main(){
int r, c, temp= 0;
cin >> r >> c;
int row_arr[r];
int i, j;
int mat[r][c];
for(i = 0; i < r; i++){
for(j = 0; j < c; j++)
cin >> mat[i][j];
}
for(i = 0; i < r; i++){
temp = mat[i][0];
for(j = 0; j < c; j++){
if(temp < mat[i][j]){
temp = mat[i][j];
}
}
cout<<temp<<endl;
}
return 0;
}
No comments:
Post a Comment