
- 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 column in a matrix in C++
Consider we have a matrix, our task is to find the maximum element of each column of that matrix and print them. This task is simple. For each column, 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 largestInEachCol(int mat[][MAX], int rows, int cols) { for (int i = 0; i < cols; i++) { int max_col_element = mat[0][i]; for (int j = 1; j < rows; j++) { if (mat[j][i] > max_col_element) max_col_element = mat[j][i]; } cout << max_col_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 } }; largestInEachCol(mat, row, col); }
Output
23 84 44 81
- Related Articles
- Find maximum element of each row in a matrix in C++
- Find the maximum element of each row in a matrix using Python
- How to find the maximum value for each column of a matrix in R?
- Find column with maximum sum in a Matrix using C++.
- Find pair with maximum difference in any column of a Matrix in C++
- Program to find the maximum element in a Matrix in C++
- How to find the percentage of zeros in each column of a matrix in R?
- How to find the number of zeros in each column of a matrix in R?
- Program to find smallest intersecting element of each row in a matrix in Python
- 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
- Find Maximum side length of square in a Matrix in C++
- How to find the index of an element in a matrix column based on some condition in R?
- How to find the maximum value in each matrix stored in an R list?
- Find the original matrix when largest element in a row and a column are given in Python

Advertisements