# C Program to generate sparse matrix.

C Program to generate sparse matrix.
A sparse matrix is a matrix that allows special techniques to take advantage of the large number of zero elements.Sparse matrix is very useful in engineering field, when solving the partial differentiation equations. Read more about how to generate sparse matrix.

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>#include<conio.h>void main(){ int A[10][10],B[10][3],m,n,s=0,i,j; clrscr(); printf("nEnter the order m x n of the sparse matrixn"); scanf("%d%d",&m,&n); printf("nEnter the elements in the sparse matrix(mostly zeroes)n"); for(i=0;i<m;i++) {  for(j=0;j<n;j++)  {   printf("n%d row and %d column:   ",i,j);   scanf("%d",&A[i][j]);  } } printf("The given matrix is:n"); for(i=0;i<m;i++) {  for(j=0;j<n;j++)  {   printf("%d ",A[i][j]);  }  printf("n"); } for(i=0;i<m;i++) {  for(j=0;j<n;j++)  {   if(A[i][j]!=0)   {    B[s][0]=A[i][j];    B[s][1]=i;    B[s][2]=j;    s++;   }  } } printf("nThe sparse matrix is given by"); printf("n"); for(i=0;i<s;i++) {  for(j=0;j<3;j++)  {   printf("%d ",B[i][j]);  }  printf("n"); } getch();}`
`Read more c programs `
`C BasicC StringsMatrix in c`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link
(c) www.c-program-example.com

# C program to find the sparse matrix

C program to accept a matrix and determine whether it is a sparse matrix or not?. A sparse matrix is a matrix, which has more zero elements than nonzero elements. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                                  Happy Coding***********************************************************/#include <stdio.h>void main (){ static int m1[10][10]; int i,j,m,n; int counter=0; printf ("Enter the order of the matixn"); scanf ("%d %d",&m,&n); printf ("Enter the co-efficients of the matixn"); 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);}       /* EN dof main() */`
`Read more Similar C ProgramsMatrix ProgramsLearn C Programming`

You can easily select the code by double clicking on the code area above.