forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.CheckSparseMatrix.cpp
More file actions
48 lines (38 loc) · 923 Bytes
/
1.CheckSparseMatrix.cpp
File metadata and controls
48 lines (38 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//To check if a given Matrix is a Sparse Matrix or not
#include<iostream>
using namespace std;
int main()
{
int r,c;
cout<<"Enter No. of Rows of Matrix :";
cin>>r;
cout<<"Enter No. of Columns of Matrix :";
cin>>c;
cout<<endl;
int a[100][100];
int zeroes = 0 ;
int nonzero = 0 ;
for(int i=0 ; i<r ; i++){
for(int j=0 ; j<c ; j++){
cout<<"Enter Element A["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
for(int i=0 ; i<r ; i++){
for(int j=0 ; j<c ; j++){
if(a[i][j] == 0)
zeroes++;
else
nonzero++;
}
}
if(zeroes > nonzero)
{
cout<<endl<<"The Given Matrix is a SPARSE MATRIX"<<endl;
}
else
{
cout<<endl<<"The Given Matrix is NOT a SPARSE MATRIX"<<endl;
}
return 0;
}