-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsparse_symmetric.c
49 lines (42 loc) · 1.2 KB
/
sparse_symmetric.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
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
typedef struct
{
int row;
int col;
int value;
} matrix;
int main()
{
int size;
printf("Enter the number of non zero elements: ");
scanf("%d", &size);
matrix m[20];
m[0].value = size;
printf("Enter the number of rows and columns: ");
scanf("%d %d", &m[0].row, &m[0].col);
printf("Enter the sparse matrix representation: ");
for (int i = 1; i <= size; i++)
scanf("%d %d %d", &m[i].row, &m[i].col, &m[i].value);
printf("Sparse matrix representation\n");
for (int i = 0; i <= size; i++)
printf("%d %d %d\n", m[i].row, m[i].col, m[i].value);
if (m[0].row != m[0].col)
{
printf("Matrix is not a square matrix\n");
return 1;
}
int is_symmetric = 0;
for (int i = 1; i <= size; i++)
{
is_symmetric = 0;
for (int j = 1; j <= size; j++)
if (m[i].row == m[j].col && m[i].col == m[j].row && m[i].value == m[j].value)
is_symmetric = 1;
if (is_symmetric == 0)
{
printf("Matrix is not symmetric\n");
return 1;
}
}
printf("Matrix is sparse symmetric\n");
}