-
Notifications
You must be signed in to change notification settings - Fork 0
/
symm.c
67 lines (55 loc) · 1.56 KB
/
symm.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define ROWS 4
#define COLS 4
#include <stdio.h>
#include <stdbool.h>
int main() {
int i, j, arr1[ROWS][COLS], arr2[ROWS][COLS];
bool isSymmetric = false;
// Initialising first matrix
printf("Enter elements of 1st Matrix: \n\n");
for(i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &arr1[i][j]);
}
}
// Initialising Second Matrix
printf("Enter elements of 2nd Matrix: \n\n");
for(i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &arr2[i][j]);
}
}
// Displaying the 2 Matrices
printf("\nHere are the 2 4x4 Matrices: \n");
printf("MATRIX 1\n");
for(i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
printf("%d\t", arr1[i][j]);
}
printf("\n");
}
for(i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
printf("%d\t", arr2[i][j]);
}
printf("\n");
}
// Algorithm to check for Symmetricity
printf("MATRIX 2\n");
for(i = 0; i < ROWS; i++) {
for(j = 0; j < COLS; j++) {
if (arr1[i][j] == arr2[j][i]) {
isSymmetric = true;
}
}
}
if(isSymmetric) {
printf("\nHOORAY !! Your Matrices are symmetric !!");
}
else {
printf("\n:( Unsymmetric matrices !");
}
return 0;
}