#include <stdio.
h> // Display sparse representation
printf("\nSparse Matrix Representation
int main() { (row col value):\n");
int m, n, i, j, count = 0; for (i = 0; i <= count; i++) {
printf("%d\t%d\t%d\n", sparse[i][0],
printf("Enter rows and columns of matrix: sparse[i][1], sparse[i][2]);
"); }
scanf("%d%d", &m, &n);
// Transpose sparse matrix
int mat[m][n]; int transpose[count + 1][3];
transpose[0][0] = sparse[0][1];
printf("Enter elements of the matrix:\n"); transpose[0][1] = sparse[0][0];
for (i = 0; i < m; i++) { transpose[0][2] = sparse[0][2];
for (j = 0; j < n; j++) {
scanf("%d", &mat[i][j]); k = 1;
if (mat[i][j] != 0) { for (j = 0; j < n; j++) {
count++; for (i = 1; i <= count; i++) {
} if (sparse[i][1] == j) {
} transpose[k][0] = sparse[i][1];
} transpose[k][1] = sparse[i][0];
transpose[k][2] = sparse[i][2];
// Sparse representation (count+1 rows, 3 k++;
cols) }
int sparse[count + 1][3]; }
sparse[0][0] = m; }
sparse[0][1] = n;
sparse[0][2] = count; // Display transpose sparse matrix
printf("\nTranspose Sparse Matrix
int k = 1; Representation (row col value):\n");
for (i = 0; i < m; i++) { for (i = 0; i <= count; i++) {
for (j = 0; j < n; j++) { printf("%d\t%d\t%d\n", transpose[i][0],
if (mat[i][j] != 0) { transpose[i][1], transpose[i][2]);
sparse[k][0] = i; }
sparse[k][1] = j;
sparse[k][2] = mat[i][j]; return 0;
k++; }
}
}
}