text: Count rows with sum exceeding sum of the remaining Matrix | C # program to implement the above approach ; Function to count the number of rows whose sum exceeds the sum of elements of the remaining matrix ; Stores the matrix dimensions ; To store the result ; Stores the total sum of the matrix elements ; Calculate the total sum ; Traverse to check for each row ; Stores the sum of elements of the current row ; Calculate the sum of elements of the current row ; If sum of current row exceeds the sum of rest of the matrix ; Increase count ; Print the result ; Driver Code ; Given matrix ; Function Call
code: using System ; class GFG { static void countRows ( int [ , ] mat ) { int n = mat . GetLength ( 0 ) ; int m = mat . GetLength ( 1 ) ; int count = 0 ; int totalSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { totalSum += mat [ i , j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { int currSum = 0 ; for ( int j = 0 ; j < m ; j ++ ) { currSum += mat [ i , j ] ; } if ( currSum > totalSum - currSum ) count ++ ; } Console . WriteLine ( count ) ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 2 , - 1 , 5 } , { - 3 , 0 , - 2 } , { 5 , 1 , 2 } } ; countRows ( mat ) ; } }