Skip to content

luc065.c

Problem Statement

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

Metadata

Property Detail
Author Amit Dutta amitdutta4255@gmail.com
Date 08 Feb 2026
License MIT License (See the LICENSE file for details)

Actions

Raw View on GitHub

💡 You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int mat[10][10], n, i, j;
    int is_symmetric = 1;

    printf("Enter the size of the square matrix (max 10): ");
    scanf("%d", &n);

    printf("Enter elements of the %dx%d matrix:\n", n, n);
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%d", &mat[i][j]);
        }
    }

    // Check for symmetry: mat[i][j] must equal mat[j][i]
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (mat[i][j] != mat[j][i])
            {
                is_symmetric = 0;
                break;
            }
        }
        if (is_symmetric == 0)
            break;
    }

    if (is_symmetric)
        printf("\nThe matrix is Symmetric.\n");
    else
        printf("\nThe matrix is NOT Symmetric.\n");

    return 0;
}