-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymmetricmatrix.c
More file actions
43 lines (35 loc) · 1.01 KB
/
symmetricmatrix.c
File metadata and controls
43 lines (35 loc) · 1.01 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
#include <stdio.h>
int main() {
int rows, cols, i, j, flag = 1;
// Input the number of rows and columns
printf("Enter the number of rows and columns of the matrix: ");
scanf("%d %d", &rows, &cols);
// A matrix must be square (rows == cols) to be symmetric
if (rows != cols) {
printf("Matrix is not symmetric (must be square).\n");
return 0;
}
int matrix[rows][cols];
// Input elements of the matrix
printf("Enter elements of the matrix:\n");
for(i = 0; i < rows; ++i) {
for(j = 0; j < cols; ++j) {
scanf("%d", &matrix[i][j]);
}
}
// Check if the matrix is symmetric
for(i = 0; i < rows; ++i) {
for(j = 0; j < cols; ++j) {
if(matrix[i][j] != matrix[j][i]) {
flag = 0;
break;
}
}
}
if(flag) {
printf("The matrix is symmetric.\n");
} else {
printf("The matrix is not symmetric.\n");
}
return 0;
}