

- 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
Number of elements greater than modified mean in matrix in C++
<p>The modified mean of the matrix is defined as follows...</p><p>(sum(row-wise min) + sum(column-wise max)) / (row_size + column_size)</p><p>Let's see an example.</p><pre class="result notranslate">1 2 3 4 5 6 7 8 9</pre><p>mean = (sum(1 + 4 + 7) + sum(7 + 8 + 9)) / (3 + 3)</p><p>We have to find the mean first and then count the number of elements that are greater than mean.</p><p>If we take the above example, then we will get 3 as the count. There are 3 elements that are greater than the mean which is 6.</p><h2>Algorithm</h2><ul class="list"><li><p>Initialise the matrix.</p></li><li><p>Find the row-wise minimum elements sum.</p></li><li><p>Find the column-wise maximum elements sum.</p></li><li><p>Then find the mean with above mentioned formula.</p></li><li><p>Now, count the number of elements greater than the mean of the matrix.</p></li></ul><h2>Implementation</h2><p>Following is the implementation of the above algorithm in C++</p><pre class="demo-code notranslate language-cpp" data-lang="cpp">#include <bits/stdc++.h> using namespace std; #define m 3 #define n 3 int getElementCountGreaterThanMean(int matrix[][n]) { int rowSum = 0; for (int i = 0; i < m; i++) { int min = matrix[i][0]; for (int j = 1; j < n; j++) { if (matrix[i][j] < min){ min = matrix[i][j]; } } rowSum += min; } int colSum = 0; for (int i = 0; i < n; i++) { int max = matrix[0][i]; for (int j = 1; j < m; j++) { if (max < matrix[j][i]) { max = matrix[j][i]; } } colSum += max; } int mean = (rowSum + colSum) / (m + n); int count = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (mean < matrix[i][j]) { count++; } } } return count; } int main() { int matrix[m][n] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; cout << getElementCountGreaterThanMean(matrix) << endl; return 0; }</pre><h2>Output</h2><p>If you run the above code, then you will get the following result.</p><pre class="result notranslate">3</pre>
- Related Questions & Answers
- Python – Sort Matrix by Number of elements greater than its previous element
- Program to find out the number of consecutive elements in a matrix whose gcd is greater than 1 in Python
- Find the number of elements greater than k in a sorted array using C++
- Python - Number of values greater than K in list
- Kth prime number greater than N in C++
- Find the Number of segments where all elements are greater than X using C++
- Finding element greater than its adjacent elements in JavaScript
- How to calculate the number of elements greater than a certain value in a vector in R?
- Count subarrays with all elements greater than K in C++
- Mask array elements greater than a given value in Numpy
- Smallest prime number just greater than the specified number in JavaScript
- Count number of substrings with numeric value greater than X in C++
- Retaining array elements greater than cumulative sum using reduce() in JavaScript
- Largest even digit number not greater than N in C++
- Count the number of words having sum of ASCII values less than and greater than k in C++
Advertisements