-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.c
More file actions
41 lines (40 loc) · 811 Bytes
/
Copy path5.c
File metadata and controls
41 lines (40 loc) · 811 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
//SPARSE MATRIX OR NOT
#include<stdio.h>
int main()
{
int n,m,a[100][100],i,j,k=0,t=0;
scanf("%d %d",&n,&m);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]==0)
k++;
else
t++;
}
}
if(k>t)
printf("given matrix is a sparse matrix\n");
else
printf("not a sparse matrix\n");
printf("triplet representation\n");
printf("%d %d %d\n",t,t,t);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]!=0)
printf("%d %d %d",i,j,a[i][j]);
}
printf("\n");
}
return 0;
}