C program for sparse matrix



 
#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);
 
}

Output:

C programs, C programming, C example, Matrix

Post a Comment

  1. minecraft java Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.

    ReplyDelete

 
Top