C++ Program to add and subtract 2 sparse matrices

C++ Program to add and subtract 2 sparse matrices.

/**************************************************************	
	Author: Arun Vishnu M V
	Web: www.arunmvishnu.com
	Description: C++ Program to add and subtract 2 sparse matrices
***************************************************************/
#include<conio.h>   	
#include<iostream.h> 
#include<process.h>  

int main()
{
   clrscr();
   int sparse1[10][3],sparse2[10][3],sum[10][3],diff[10][3];
   int m,n,p,q,t1,t2,s,d,element;
   int i,j;
   cout<<"Enter the number of rows and columns : ";
   cin>>m>>n;
   t1=t2=0;

   cout<<"\nEnter the first matrix("<>element;
	 if(element!=0)
	 {
	    t1=t1+1;
	    sparse1[t1][1]=i;
	    sparse1[t1][2]=j;
	    sparse1[t1][3]=element;
	 }
      }
   }
   sparse1[0][1]=m;
   sparse1[0][2]=n;
   sparse1[0][3]=t1;
   cout<<"\nEnter the second matrix("<>element;
	 if(element!=0)
	 {
	    t2=t2+1;
	    sparse2[t2][1]=i;
	    sparse2[t2][2]=j;
	    sparse2[t2][3]=element;
	 }
      }
   }
   sparse2[0][1]=m;
   sparse2[0][2]=n;
   sparse2[0][3]=t2;

   // displaying the first sparse matrix
   cout<<"\n\nThe first sparse matrix is :\n\nRow\tColumn\tElement";
   cout<<"\n-----------------------\n";
   for(i=0;i<=t1;i++)
   {
      cout<

You may also like...

Leave a Reply

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