Skip to content

Commit 7d9258f

Browse files
authored
Merge pull request zapellass123#478 from anu053/main
Create sparse_matrix.c
2 parents acf0b07 + aa888b5 commit 7d9258f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

sparse_matrix.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int m,n,c,d,a[10][10],count=0;
5+
printf(" enter the number of rows and columns:\n");
6+
scanf("%d%d",&m,&n);
7+
printf("enter the element the matrix:\n");
8+
for(c=0;c<m;c++)
9+
{
10+
for(d=0;d<n;d++)
11+
{
12+
scanf("%d",&a[c][d]);
13+
}
14+
}
15+
printf("elements are:\n");
16+
for(c=0;c<m;c++)
17+
{
18+
for(d=0;d<n;d++)
19+
{
20+
printf("%d\t",a[c][d]);
21+
}
22+
printf("\n");
23+
}
24+
for(c=0;c<m;c++)
25+
{
26+
for(d=0;d<n;d++)
27+
{
28+
if(a[c][d]==0)
29+
count++;
30+
}
31+
}
32+
if(count>((m*n)/2))
33+
{
34+
printf("sparse matrix");
35+
}
36+
else
37+
{
38+
printf("not a sparse matrix");
39+
}
40+
return 0;
41+
}

0 commit comments

Comments
 (0)