-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompactMatrix.c
More file actions
49 lines (44 loc) · 1.02 KB
/
Copy pathcompactMatrix.c
File metadata and controls
49 lines (44 loc) · 1.02 KB
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
38
39
40
41
42
43
44
45
46
47
/*Author : Anna Tony
Date : 16-03-2025
Description : compact matrix
Version : 1.0 */
#include <stdio.h>
int main(){
int row,col;
printf("\nEnter the row and column : ");
scanf("%d%d",&row,&col);
int mat[row][col];
printf("\nEnter the elements : ");
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
scanf("%d",&mat[i][j]);
}
}
int size=0;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(mat[i][j]!=0){
size++;
}
}
}
int matC[3][size];
int k=0;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(mat[i][j]!=0){
matC[0][k]=i;
matC[1][k]=j;
matC[2][k]=mat[i][j];
k++;
}
}
}
for (int i=0;i<3;i++){
for (int j=0;j<size;j++){
printf("%d\t",matC[i][j]);
}
printf("\n");
}
return 0;
}