forked from Shreya1600/Hacktoberfest-C-Program
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquareMatrix.c
67 lines (59 loc) · 1.95 KB
/
SquareMatrix.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
#include<stdio.h>
int main()
{
printf("\n\n\t\tProgram to check whether given Square Matrix is symmetric or not\n\n\n");
int c, d, a[10][10], b[10][10], n, temp;
printf("\nEnter the dimension of the matrix: \n\n");
scanf("%d", &n);
printf("\nEnter the %d elements of the matrix: \n\n",n*n);
for(c = 0; c < n; c++) // to iterate the rows
for(d = 0; d < n; d++) // to iterate the columns
scanf("%d", &a[c][d]);
// finding transpose of a matrix and storing it in b[][]
for(c = 0; c < n; c++) // to iterate the rows
for(d = 0; d < n; d++) //to iterate the columns
b[d][c] = a[c][d];
// printing the original matrix
printf("\n\nThe original matrix is: \n\n");
for(c = 0; c < n; c++) // to iterate the rows
{
for(d = 0; d < n; d++) // to iterate the columns
{
printf("%d\t", a[c][d]);
}
printf("\n");
}
// printing the transpose of the entered matrix
printf("\n\nThe Transpose matrix is: \n\n");
for(c = 0; c < n; c++) // to iterate the rows
{
for(d = 0; d < n; d++) // to iterate the columns
{
printf("%d\t", b[c][d]);
}
printf("\n");
}
// checking if the original matrix is same as its transpose
for(c = 0; c < n; c++) // to iterate the rows
{
for(d = 0; d < n; d++) // to iterate the columns
{
/*
even if they differ by a single element,
the matrix is not symmetric
*/
if(a[c][d] != b[c][d])
{
printf("\n\nMatrix is not Symmetric\n\n");
exit(0); // a system defined method to terminate the program
}
}
}
/*
if the program is not terminated yet,
it means the matrix is symmetric
*/
printf("\n\nMatrix is Symmetric\n\n");
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}