C Program to Check Whether a Matrix is Symmetric

Subject: PPS (Programming for Problem Solving)

Contributed By: Sanjay

Created At: February 3, 2025

Question:


Write a C Program to Check Whether a Matrix is Symmetric

Explanation Video:

Custom Image

Explanation:

 

A matrix is symmetric if it is equal to its transpose. This means arr[i][j] == arr[j][i] for all elements.

Source Code:
#include <stdio.h>

int main() {
    int arr[3][3] = {{1, 2, 3}, {2, 4, 5}, {3, 5, 6}};
    int isSymmetric = 1;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (arr[i][j] != arr[j][i]) {
                isSymmetric = 0;
                break;
            }
        }
    }

    if (isSymmetric)
        printf("The matrix is Symmetric\n");
    else
        printf("The matrix is not Symmetric\n");

    return 0;
}
Output:
The matrix is Symmetric
Share this Article & Support Us:
Status
printf('Loading...');