From bfdc2f39de913a869efb59ee34be829062215593 Mon Sep 17 00:00:00 2001 From: Anurag Dwivedi Date: Sun, 24 Oct 2021 11:23:33 +0530 Subject: [PATCH] Create Check_for_sparse.cpp Add CPP Code --- data-structures/Check_for_sparse.cpp | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 data-structures/Check_for_sparse.cpp 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"<