Raju is the maths teacher in high secondary school and provided mark sheet to students.In this class room, students are arranged in the form of rows and columns. Raju needs to find the highest mark in each rows. Help him to find out.
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
Answers
Answer:
INPUT FORMAT
Explanation:
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.
Answer:
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
// Function to find the maximum
// element of each column.
void largestInColumn(int mat[][MAX], int rows, int cols)
{
for (int i = 0; i < cols; i++) {
// initialize the maximum element
// with 0
int maxm = mat[0][i];
// Run the inner loop for rows
for (int j = 1; j < rows; j++) {
// check if any element is greater
// than the maximum element
// of the column and replace it
if (mat[j][i] > maxm)
maxm = mat[j][i];
}
// print the largest element of the column
cout << maxm << endl;
}
}
// Driver code
int main()
{
int n = 3, m = 3;
int mat[][MAX] = { {22, 23, 25},
{25, 22, 26},
{26,27, 23 }};
largestInColumn(mat, n, m);
return 0;
}
Explanation:
Hope thhis is helpful