
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Print index of columns sorted by count of zeroes in the Given Matrix in C Program.
Given an array of size NxM where N number of rows and M number of columns, and the task is to print the number of zeroes in every column of a corresponding matrix after performing sort operation on the basis of number of zeros present in any column.
For example if the 1st column contain 1 zeros and 2nd column doesn’t contain any number of zeros and 3rd column contain 2 zeroes then the result should be − 3 1 2.
Example
Input: 0 0 0 1 1 1 1 0 1 Output: 1 3 2
Explanation
Note − the matrix is considered started from index 1.
Example
#include <bits/stdc++.h> #define row 3 #define col 3 using namespace std; void sorting(int arr[row][col]){ vector<pair<int, int> >count_zero; for (int i = 0; i < col; i++){ int count = 0; for (int j = 0; j < row; j++){ if (arr[j][i] == 0) count++; } count_zero.push_back(make_pair(count, i)); } sort(count_zero.begin(), count_zero.end()); for (int i = 0; i < col; i++) cout<< count_zero[i].second + 1 << " "; } int main(){ int array[row][col] = { { 0, 0, 0 }, { 1, 1, 1 }, { 1, 0, 1 } }; cout<<"sorted order of zeroes count is : "; sorting(array); return 0; }
Output
if we run the above program then it will generate the following output
sorted order of zeroes count is : 1 3 2
- Related Articles
- Count all the columns in a matrix which are sorted in descending in C++
- Print k different sorted permutations of a given array in C Program.
- Program to count number of square submatix of 1s in the given matrix in C++
- Print maximum sum square sub-matrix of given size in C Program.
- Count all sorted rows in a matrix in C++
- Count no. of columns that are not sorted in increasing order in C++
- C/C++ Program to Count trailing zeroes in factorial of a number?
- Write a program in Python to print numeric index array with sorted distinct values in a given series
- Print lower triangular matrix pattern from given array in C Program.
- Program to count number of islands in a given matrix in Python
- Print the matrix diagonally downwards in C Program.
- Program to count number of square submatrices in given binary matrix in Python
- Print a given matrix in zigzag form in C++
- How to print number of islands in a given matrix using C#?
- Count columns to be deleted to make each row sorted in C++

Advertisements