### Program 136:To find whether given matrix is Sparse Matrix or not

Program 136:

```#include<stdio.h>
main()
{
int i,j,rows,col,count=0;
printf("Enter number of rows and columns of a matrix\n");
scanf("%d %d",&rows,&col);
int a[rows][col];

//Taking input of matrix
printf("Enter Matrix 1\n");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)
{
count++;
}
}
}

printf("Given /matrix is\n");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
}

printf("\n");
}

if(count>((rows*col)/2))
{
printf("Number of zeros is %d\n",count);
printf("Number of elements other than zero are %d\n",(rows*col)-count);
printf("As zeros are greater than remaining elements\n");
printf("Hence Given Matrix is Sparse Matrix \n");
}
else
{
printf("Number of zeros is %d\n",count);
printf("Number of elements other than zero are %d\n",(rows*col)-count);
printf("As zeros are lesser than remaining elements\n");
printf("Hence Given Matrix is not Sparse Matrix \n");
}

}

```
Explanation:

//Coming Soon...

Output:

After 1st run:

After 2nd run:

#### Post a comment

 Donate Buy me a coffee \$2.00 USD Buy me a burger \$5.00 USD Buy me a pizza \$10.00 USD
 Compiler Used by me C-Free 5.0(Recommended) Other Compilers Code Blocks(Recommended) Online Compilers Ideone(Remember to give input before executing online where ever necessary)