-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl3q3.c
43 lines (43 loc) · 925 Bytes
/
l3q3.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
42
43
#include <stdio.h>
#include <malloc.h>
int l3q3()
{
int m,count=0,n;
printf("ENTER THE DIMENSIONS OF MATRIX(rows and columns)\n");
scanf("%d%d",&m,&n);
int **b = (int **)malloc(m*sizeof(int *));
for(int i=0;i<m;i++)
{
b[i]=(int *)malloc(n*sizeof(int));
}
printf("ENTER THE ELEMENTS IN ROW MAJOR FASHION\n");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(b[i][j]==0)
{
count++;
}
}
}
for(int i=0;i<m;i++)
{
free(b[i]);
}
free(b);
if( count>0.5*(m*n) )
{
printf("Yes , the matrix is a sparse matrix\n");
}
else
printf("No , the matrix is not a sparse matrix\n");
return 0;
}