diff --git a/data-structures/Check_for_sparse.cpp b/data-structures/Check_for_sparse.cpp new file mode 100644 index 00000000..b592fa37 --- /dev/null +++ b/data-structures/Check_for_sparse.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +int main () { + int i, j, count = 0; + int row , col; + cin>>row>>col; + int a[row][col]; + for (i = 0; i < row; ++i) { + for (j = 0; j < col; ++j){ + cin>>a[i][j]; + } + } + for (i = 0; i < row; ++i) { + for (j = 0; j < col; ++j){ + if (a[i][j] == 0) + count++; + } + } + cout<<"The matrix is "< ((row * col)/ 2)) + cout<<"This is a sparse matrix"<