Ad

Chapter - 9: Arrays

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


Ad
#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;

}
Ad

© 2024 Garbage Valuegarbage value logo