commit e5d487757cd2971022b504377e8fc25866eba309 Author: Amneesh Singh Date: Tue Dec 27 16:42:01 2022 +0530 exp 1: init Signed-off-by: Amneesh Singh diff --git a/1.c b/1.c new file mode 100644 index 0000000..11a85dc --- /dev/null +++ b/1.c @@ -0,0 +1,27 @@ +#include + +int main() { + const int ORDER = 3; + int mx[ORDER][ORDER]; + int n = 0; + + for (int i = 0; i < ORDER; i++) + for (int j = 0; j < ORDER; j++) { + printf("Element at (r, c) = (%d, %d): ", i, j); + scanf("%d", &mx[i][j]); + if (mx[i][j]) + n++; + } + + int sparse[n][3]; + + for (int i = 0, k = 0; i < ORDER && k < n; i++) + for (int j = 0; j < ORDER; j++) { + if (mx[i][j]) + sparse[k][0] = i, sparse[k][1] = j, sparse[k][2] = mx[i][j], k++; + } + + printf("\nSparse matrix (row, column, value):\n"); + for (int i = 0; i < n; i++) + printf("(%d, %d, %d)\n", sparse[i][0], sparse[i][1], sparse[i][2]); +} diff --git a/1.png b/1.png new file mode 100644 index 0000000..aa66e58 Binary files /dev/null and b/1.png differ