-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSparseMatrix.c
37 lines (30 loc) · 872 Bytes
/
SparseMatrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// C Program to check & print values of a sparse matrix
#include <stdio.h>
int matrix[10][10], rows, columns, i, j;
int main(){ //Main Function
printf("Enter no. of rows & columns: ");
scanf("%d %d", &rows, &columns); //Getting no. of Rows & Columns
// Getting matrix
for(i=0; i < rows; i++){
for(j=0; j < columns; j++){
printf("\nEnter Matrix[%d][%d] value: ", i, j);
scanf("%d", &matrix[i][j]); //getting the matrix
}
}
// Printing matrix
printf("\nEntered Matrix:\n");
for(i=0; i < rows; i++){
for(j=0; j < columns; j++){
printf("%d ", matrix[i][j]); //getting the matrix
}
printf("\n");
}
// Checking & Printing Sparse Matrix values
printf("\nVALUE\tROW\tCOLUMN\n");
for(i=0; i < rows; i++){
for(j=0; j < columns; j++){
if(matrix[i][j] != 0)
printf("%d\t%d\t%d\n", matrix[i][j], i, j);
}
}
}