# Representation of Sparse Matrix (Using C++)

In numerical analysis and scientific computing, a sparse matrix is a two-dimensional matrix in which most of the elements are zero.

## SPARSE MATRIX

A sparse matrix is a two-dimensional array in which most of the elements are zero. The number of zero elements should be greater than half of the total number of elements.

## REPRESENTATION OF A SPARSE MATRIX ```#include <bits/stdc++.h>
using namespace std ;

int main ()
{
const int size =20; int l=1;
cout<<"SPARSE MATRIX"<<endl;
int A[size][size],B[size], R , C,Z,nz;
cout<<"Enter the no. Rows in  the matrix   :";
cin>> R;
cout<<"Enter the no. columns in  the matrix    :";
cin>> C;
for(int i=0 ;i<R;i++)
for(int j=0 ;j<C;j++)
{
cout<<"Enter Element A["<<i+1<<"]["<<j+1<<"]   :";
cin>>A[i][j];
if(A[i][j]==0) Z++;
else nz++;
}
if(Z>((R*C)/2))
{    B= R;
B= C;
B= nz;
for(int i=0;i<R;i++)
for(int j=0;j<C;j++)
if(A[i][j]!=0)
{
B[l]= i;
B[l]= j;
B[l]= A[i][j];
l++;
}
}
cout<<"The Sparse matrix is given by    :\n";
for(int i=0;i<l;i++)
{
for(int j=0;j<3;j++)
cout<<B[i][j]<<"   ";
cout<<endl;
}

return 0;
}

```

## OUTPUT 