#include <stdio.h>
void main ()
{
static int m1[10][10];
int i,j,m,n;
int counter=0;
printf (“Enter the order of the matrix\n”);
scanf (“%d %d”,&m,&n);
printf (“Enter the co-efficient s of the matrix\n”);
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf (“%d”,&m1[i][j]);
if (m1[i][j]==0)
{
++counter;
}
}
}
if (counter>((m*n)/2))
{
printf (“The given matrix is sparse matrix \n”);
}
else
printf (“The given matrix is not a sparse matrix \n”);
printf (“There are %d number of zeros”,counter);
} /* END of main() */
/*———————————————-
Output
Enter the order of the matrix
2 2
Enter the co-efficient s of the matrix
1 2
3 4
The given matrix is not a sparse matrix
There are 0 number of zeros
Run 2
Enter the order of the matrix
3 3
Enter the co-efficient s of the matrix
1 0 0
0 0 1
0 1 0
The given matrix is sparse matrix
There are 6 number of zeros
———————————————–*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to accept a matrix of order M x N and store its elements and interchange the main diagonal elements of the matrix with that of the secondary diagonal elements
- C program to accept a matrix of order MxN and find the trace and normal of a matrix HINT:Trace is defined as the sum of main diagonal elements and Normal is defined as square root of the sum of all the elements
- C program to find accept a matrix of order M x N and find the sum of the main diagonal and off diagonal elements
- C program to accept a matrix of given order and interchange any two rows and columns in the original matrix
- C program to accept a matrix of order M x N and find the sum of each row and each column of a matrix
