// C# program to find if
// a matrix is symmetric.
using System;
public class GFG {
static void checkHV(int[, ] arr, int N, int M)
{
// Initializing as both horizontal
// and vertical symmetric.
bool horizontal = true;
bool vertical = true;
// Checking for Horizontal Symmetry.
// We compare first row with last
// row, second row with second
// last row and so on.
for (int j = 0, k = N - 1; j < N / 2; j++, k--) {
// Checking each cell of a column.
for (int i = 0; i < M; i++) {
// check if every cell is identical
if (arr[i, j] != arr[i, k]) {
horizontal = false;
break;
}
}
}
// Checking for Vertical Symmetry. We compare
// first column with last column, second column
// with second last column and so on.
for (int i = 0, k = M - 1; i < M / 2; i++, k--) {
// Checking each cell of a row.
for (int j = 0; j < N; j++) {
// check if every cell is identical
if (arr[i, j] != arr[k, j]) {
horizontal = false;
break;
}
}
}
if (!horizontal && !vertical)
Console.WriteLine("NO");
else if (horizontal && !vertical)
Console.WriteLine("HORIZONTAL");
else if (vertical && !horizontal)
Console.WriteLine("VERTICAL");
else
Console.WriteLine("BOTH");
}
// Driver Code
static public void Main()
{
int[, ] mat
= { { 1, 0, 1 }, { 0, 0, 0 }, { 1, 0, 1 } };
checkHV(mat, 3, 3);
}
}
// This code is contributed by vt_m.