From 86a241bff51018cd718925f9da8685a37c3fce9e Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Tue, 27 Mar 2018 17:51:33 +0200 Subject: [PATCH] fixed bugs and improved the code --- Others/Sparse matrix.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Others/Sparse matrix.cpp b/Others/Sparse matrix.cpp index 19452dfee..40073c345 100644 --- a/Others/Sparse matrix.cpp +++ b/Others/Sparse matrix.cpp @@ -1,27 +1,40 @@ /*A sparse matrix is a matrix which has number of zeroes greater than (m*n)/2, where m and n are the dimensions of the matrix.*/ #include +using namespace std; + int main() { - int m,n,i,j,c=0; - cout << "Enter dimensions of matrix:"; + int m,n; + int counterZeros=0; + cout << "Enter dimensions of matrix (seperated with space): "; cin >> m >> n; int a[m][n]; cout << "Enter matrix elements:"; - for(i=0;> a[i][j]; - } - for(i=0;i> a[i][j]; } } - if(c>((m*n)/2)) //Checking for sparse matrix + + // counts the zero's + for(int i=0;i((m*n)/2)) //Checking for sparse matrix cout << "Sparse matrix"; else cout << "Not a sparse matrix";