Oct 3, 2011

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 info@c-program-example.com
* 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 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",&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 Programs
Matrix Programs
Learn C Programming
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

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

our page!

Share this program with your Facebook friends now! by liking it


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

Like to get updates right inside your feed reader? Grab our feed!