C++ Program to find the transpose of a Sparse matrix

C++ Program to find the transpose of a Sparse matrix.

/**************************************************************	
	Author: Arun Vishnu M V
	Web: www.arunmvishnu.com
	Description: C++ Program to find the transpose of a Sparse matrix 
***************************************************************/
#include>m>>n;
   t=0;
	// assigning the value of matrix
   
   cout<<"\nEnter the matrix:\n";
   for(i=1;i<=m;i++)
   {
      for(j=1;j<=n;j++)
      {
	 cin>>element;
	 if(element!=0)
	 {
	    t=t+1;
	    sparse[t][1]=i;
	    sparse[t][2]=j;
	    sparse[t][3]=element;
	 }
      }
   }
   cout<<"\n\nThe sparse matrix is :\n\nRow\tColumn\tElement";

// displaying the matrix of non-zero value
   cout<<"\n\n"<0)
   {
      for(i=1;i<=n;i++)
      {
	 for(j=1;j<=t;j++)
	 {
	    if(sparse[j][2]==i)
	    {
		transpose[q][1]=sparse[j][2];
		transpose[q][2]=sparse[j][1];
		transpose[q][3]=sparse[j][3];
		q=q+1;
	    }
	 }
      }
   }

   cout<<"\n\nThe transpose of the sparse matrix :\n ";
   cout<<"\nRow\tColumn\tElement\n\n";
   cout<

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *