FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
C-Plus-Plus/others/Sparse matrix.cpp at master · SelfCodeLearning/C-Plus-Plus · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SelfCodeLearning
/
C-Plus-Plus
Public
forked from
TheAlgorithms/C-Plus-Plus
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
C-Plus-Plus
/
others
/
Sparse matrix.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (37 loc) · 901 Bytes
Breadcrumbs
C-Plus-Plus
/
others
/
Sparse matrix.cpp
Copy path
File metadata and controls
41 lines (37 loc) · 901 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
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
<
iostream
>
using
namespace
std
;
int
main
()
{
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:
"
;
cout <<
"
\n
"
;
//
reads the matrix from stdin
for
(
int
i =
0
; i < m; i++)
{
for
(
int
j =
0
; j < n; j++)
{
cout <<
"
element?
"
;
cin >> a[i][j];
}
}
//
counts the zero's
for
(
int
i =
0
; i < m; i++)
{
for
(
int
j =
0
; j < n; j++)
{
if
(a[i][j] ==
0
)
counterZeros++;
//
Counting number of zeroes
}
}
//
makes sure the matrix is a sparse matrix
if
(counterZeros > ((m * n) /
2
))
//
Checking for sparse matrix
cout <<
"
Sparse matrix
"
;
else
cout <<
"
Not a sparse matrix
"
;
}
Back
|
FazBrowse Home
|
New Git URL