| 4 | int nonZero; |
| 5 | |
| 6 | void sparseMatrix(int arr[100][100],int rows,int columns){ |
| 7 | |
| 8 | int crr[rows][nonZero],p=0,q=0; |
| 9 | |
| 10 | for(int i=0;i<rows;i++){ |
| 11 | for(int j=0;j<columns;j++){ |
| 12 | |
| 13 | if (arr[i][j]>0){ |
| 14 | crr[p][q]=i; |
| 15 | crr[p+1][q]=j; |
| 16 | crr[p+2][q]=arr[i][j]; |
| 17 | q++; |
| 18 | |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | for(int f=0; f<rows;f++){ |
| 24 | for(int g=0;g<nonZero;g++){ |
| 25 | printf("%d ", crr[f][g]); |
| 26 | } |
| 27 | printf("\n"); |
| 28 | } |
| 29 | |
| 30 | } |
| 31 | |
| 32 | int main() |
| 33 | { |