Check if a given matrix is sparse or not | C # code to check if a matrix is sparse . ; Count number of zeros in the matrix ; Driver Function
using System ; class GFG { static bool isSparse ( int [ , ] array , int m , int n ) { int counter = 0 ; for ( int i = 0 ; i < m ; ++ i ) for ( int j = 0 ; j < n ; ++ j ) if ( array [ i , j ] == 0 ) ++ counter ; return ( counter > ( ( m * n ) / 2 ) ) ; } public static void Main ( ) { int [ , ] array = { { 1 , 0 , 3 } , { 0 , 0 , 4 } , { 6 , 0 , 0 } } ; int m = 3 , n = 3 ; if ( isSparse ( array , m , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }