This C Program determines the given matrix is a sparse matrix. Sparse matrix is a matrix with the majority of its elements equal to zero. This program accepts matrix and checks whether the given matrix is a sparse matrix.

Here is source code of the C program to determine if a given matrix is a sparse matrix. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program to determine if a given matrix is a sparse matrix.`

`* Sparse martix has more zero elements than nonzero elements.`

`*/`

`#include <stdio.h>`

void main ()

`{`

static int array[10][10];

int i, j, m, n;

int counter = 0;

printf("Enter the order of the matix \n");

scanf("%d %d", &m, &n);

printf("Enter the co-efficients of the matix \n");

for (i = 0; i < m; ++i)

`{`

for (j = 0; j < n; ++j)

`{`

scanf("%d", &array[i][j]);

if (array[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);

`}`

$ cc pgm86.c $ a.out Enter the order of the matix 3 3 Enter the co-efficients of the matix 10 20 30 5 10 15 3 6 9 The given matrix is not a sparse matrix There are 0 number of zeros $ a.out Enter the order of the matix 3 3 Enter the co-efficients of the matix 5 0 0 0 0 5 0 5 0 The given matrix is sparse matrix There are 6 number of zeros

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Matrix, go to C Programming Examples on Matrix. If you wish to look at programming examples on all topics, go to C Programming Examples.