#include<stdio.h>
int main()
{
int m,n, i,j, d,a[10][10];
int count = 0;
printf("\nEnter the number of rows and columns of the matrix \n\n");
scanf("%d%d",&m,&n);
printf("\nEnter the %d elements of the matrix \n\n", m*n);
for(i = 0; i< m; i++)
{
for(j = 0; j< n; j++)
{
scanf("%d", &a[i][j]);
if(a[i][j] == 0)
count++;
}
}
printf("\n\nThe entered matrix is: \n\n");
for(i = 0; i < m; i++)
{
for(j= 0; j< n; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
if(count > (m*n)/2)
printf("\n\nThe entered matrix is a sparse matrix\n\n");
else
printf("\n\nThe entered matrix is not a sparse matrix\n\n");
return 0;
}
Note: Need to be arranged in compiler after copied
OutPut:
Enter the number of rows and columns of the matrix
3
3
Enter the 9 elements of the matrix
2
3
9
0
0
0
0
0
2
The entered matrix is:
2 3 9
0 0 0
0 0 2
The entered matrix is a sparse matrix