- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this tutorial, we will be discussing a program to find the number of columns in a matrix which are sorted in descending.

For this we will be provided with a matrix. Our task is to count the number of columns in the matrix having elements sorted in descending order.

#include <bits/stdc++.h> #define MAX 100 using namespace std; //counting columns sorted in descending order int count_dcolumns(int mat[][MAX], int r, int c){ int result = 0; for (int i=0; i<c; i++){ int j; for (j=r-1; j>0; j--) if (mat[i][j-1] >= mat[i][j]) break; if (c > 1 && j == 0) result++; } return result; } int main(){ int m = 2, n = 2; int mat[][MAX] = {{1, 3}, {0, 2,}}; cout << count_dcolumns(mat, m, n); return 0; }

2

- Related Questions & Answers
- Count all sorted rows in a matrix in C++
- Count all 0s which are blocked by 1s in binary matrix in C++
- Print index of columns sorted by count of zeroes in the Given Matrix in C Program.
- Count no. of columns that are not sorted in increasing order in C++
- Python – Test if all elements are unique in columns of a Matrix
- Count elements smaller than or equal to x in a sorted matrix in C++
- Count all prefixes of the given binary array which are divisible by x in C++
- Count numbers which are divisible by all the numbers from 2 to 10 in C++
- Count all palindrome which is square of a palindrome in C++
- Count columns to be deleted to make each row sorted in C++
- Find a common element in all rows of a given row-wise sorted matrix in C++
- Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added in C++
- Python Pandas - Return a sorted copy of the index in descending order
- Absolute distinct count in a sorted array in C++?
- Count of arrays in which all adjacent elements are such that one of them divide the another in C++

Advertisements