forked from SoumyadeepMukherjee/Matrix_Manipulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sparse.c
41 lines (35 loc) · 812 Bytes
/
Sparse.c
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
/* C Program to check Matrix is a Sparse Matrix or Not */
#include<stdio.h>
int main()
{
int i, j, rows, columns, a[10][10], Total = 0;
printf("\n Please Enter Number of rows and columns : ");
scanf("%d %d", &i, &j);
printf("\n Please Enter the Matrix Elements \n");
for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &a[rows][columns]);
}
}
for(rows = 0; rows < i; rows++)
{
for(columns = 0; columns < j; columns++)
{
if(a[rows][columns] == 0)
{
Total++;
}
}
}
if(Total > (rows * columns)/2)
{
printf("\n The Matrix that you entered is a Sparse Matrix ");
}
else
{
printf("\n The Matrix that you entered is Not a Sparse Matrix ");
}
return 0;
}