-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathSparseMtrix.cpp
More file actions
40 lines (35 loc) · 708 Bytes
/
SparseMtrix.cpp
File metadata and controls
40 lines (35 loc) · 708 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
//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[r][c];
int zeroes = 0 ;
int nonzero = 0 ;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < r; j++)
{
cin >> a[i][j];
if (a[i][j] == 0)
{
zeroes++;
}
}
}
if (zeroes > (r * c) / 2)
{
cout << "The matrix is a sparse matrix";
}
else
{
cout << "The matrix is not a sparse matrix";
}
return 0;
}