Dremendo Tag Line

Input numbers in 2d array and check symmetric matrix or not in C++

Two Dimensional Array - Question 10

In this question, we will see how to input numbers in a 3X3 integer matrix (2d array) and check whether it is a symmetric matrix or not in C++ programming. To know more about two dimensional array click on the two dimensional array lesson.

Q10) Write a program in C++ to input numbers in a 3X3 integer matrix (2d array) and check whether it is a symmetric matrix or not. Symmetric matrix is such a matrix whose row elements are exactly same as column elements.

Double Dimension Array Question 10

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int a[3][3], r,c,x=0;

    cout<<"Enter 9 numbers\n";
    for(r=0; r<3; r++)
    {
        for(c=0; c<3; c++)
        {
            cin>>a[r][c];
        }
    }

    for(r=0; r<3; r++)
    {
        for(c=0; c<3; c++)
        {
            cout<<a[r][c]<<" ";
            if(a[r][c]==a[c][r])
            {
                x++;
            }
        }
        cout<<endl;
    }

    if(x==9)
    {
        cout<<"Symmetric Matrix";
    }
    else
    {
        cout<<"Not Symmetric Matrix";
    }
    return 0;
}

Output

Enter 9 numbers
2
4
5
4
9
12
5
12
15
2 4 5
4 9 12
5 12 15
Symmetric Matrix
video-poster