exp 1: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-27 16:42:01 +05:30
commit e5d487757c
2 changed files with 27 additions and 0 deletions

27
1.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h>
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]);
}

BIN
1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB