Sparse Matrix refers to only those matrix whose more than half elements are zero.Here is the program to check your matrix for Sparse Matrix and calculation of zero elements in your matrix
#include<stdio.h> /*Standard input output pre processor*/
#define MAX 15 /*size of MAX pre defined */
int main()
{
int array[MAX][MAX],i,j,m,n,count=0;
printf("\nEnter the no. of rows and columns for your matrix:- ");
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&array[i][j]);
if(array[i][j]==0)
{
count++;
}
}
}
if(count>(m*n)/2)
{
printf("\n\nThe above matrix is SPARSE MATRIX");
printf("\n\tHence their are %d number of zeros",count);
}
else
{
printf("\nThe above matrix is not a sparse matrix ");
}
return 0;
}
#include<stdio.h> /*Standard input output pre processor*/
#define MAX 15 /*size of MAX pre defined */
int main()
{
int array[MAX][MAX],i,j,m,n,count=0;
printf("\nEnter the no. of rows and columns for your matrix:- ");
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&array[i][j]);
if(array[i][j]==0)
{
count++;
}
}
}
if(count>(m*n)/2)
{
printf("\n\nThe above matrix is SPARSE MATRIX");
printf("\n\tHence their are %d number of zeros",count);
}
else
{
printf("\nThe above matrix is not a sparse matrix ");
}
return 0;
}