#include<stdio.h> main() { int arr[100][100],arr1[100][3],i,j,m,n,a=1,b=0; printf("enter the no of columns and rows\n"); scanf("%d%d",&m,&n); arr1[0][0]=m;arr1[0][1]=n; printf("enter the elements of the matrix\n"); for(i=0;i<m;i++) for(j=0;j<n;j++) { scanf("%d",&arr[i][j]); if(arr[i][j]!=0) { arr1[a][b]=i; arr1[a][b+1]=j; arr1[a][b+2]=arr[i][j]; a++; } } arr1[0][2]=a-1; printf("the sparse matrix is as follows\n"); for(i=0;i<a;i++){ for(j=0;j<3;j++) printf("%d\t",arr1[i][j]); printf("\n");} }