Chapter - 9: Arrays

Write a program to find if a square matrix is symmetric.


L
Sections
8
Exercises

A

B

C

D

E

F

G

H

I

J

K

L

1

2

3

4

5

6

7

8

9

10

11

13

14

15

16

17

18

19

#include<stdio.h>
#include<conio.h>
#define n 3
int main()
{
	int i, j;

	int mat[n][n];
	printf("Enter the elements of the of the %d by %d matrix.\n", n, n);
	for (i = 0; i<n; i++)//scanning elements
		for (j = 0; j<n; j++)
			scanf("%d", &mat[i][j]);

	for (i = 0; i<n; i++)//checking symmetry
	{
		for (j = 0; j<n; j++)
		{
			if (mat[i][j] != mat[j][i])
			{
				printf("\nThis is not a symmetric matrix.\n");
				_getch();
				return 0;
			}
			else
				continue;
		}
	}
	if (i == n)//if it is syymetric
		printf("\nThis is a symmetric matrix.\n");

	_getch();
	return 0;

}

© 2020 Garbage Valuegarbage value logo