
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find maximum element of each row in a matrix in C++
Consider we have a matrix, our task is to find the maximum element of each row of that matrix and print them. This task is simple. For each row, reset the max, and find the max element, and print it. Let us see the code for better understanding.
Example
#include<iostream> #define MAX 10 using namespace std; void largestInEachRow(int mat[][MAX], int rows, int cols) { for (int i = 0; i < rows; i++) { int max_row_element = mat[i][0]; for (int j = 1; j < cols; j++) { if (mat[i][j] > max_row_element) max_row_element = mat[i][j]; } cout << max_row_element << endl; } } int main() { int row = 4, col = 4; int mat[][MAX] = { { 3, 4, 1, 81 }, { 1, 84, 9, 11 }, { 23, 7, 21, 1 }, { 2, 1, 44, 5 } }; largestInEachRow(mat, row, col); }
Output
81 84 23 44
- Related Articles
- JavaScript Program to Find maximum element of each row in a matrix
- Find the maximum element of each row in a matrix using Python
- Find maximum element of each column in a matrix in C++
- Find row with maximum sum in a Matrix in C++
- Maximum sum of elements from each row in the matrix in C++
- Program to find smallest intersecting element of each row in a matrix in Python
- Maximum weight path ending at any element of last row in a matrix in C++
- Python - Sort Matrix by Maximum Row element
- Find row number of a binary matrix having maximum number of 1s in C++
- Program to find the maximum element in a Matrix in C++
- Find a common element in all rows of a given row-wise sorted matrix in C++
- Find Minimum Elements in Each Row of Matrix in Java?
- C++ program to find the Sum of each Row and each Column of a Matrix
- C++ program to Replace Every Matrix Element with Maximum of GCD of Row or Column
- How to find the row products for each row in an R matrix?

Advertisements