Answer to Question #180430 in C++ for awais

Question #180430

Write a program which will ask the user to enter the size and elements for 6 different square matrices.

And then tell the user that is these symmetrical matrices or not? (A matrix (M) is said to be

symmetrical if MT = M).

Hints

• Code a function which will ask the user to enter the elements of a 2D array with R rows and C

columns. (Dynamic memory allocation will be useful here).


1
Expert's answer
2021-04-11T22:41:56-0400
#include <iostream>
using namespace std;
  
const int MAX = 100;
 
bool isSymmetric(int mat[][MAX], int N)
{
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if (mat[i][j] != mat[j][i])
                return false;
    return true;
}
int main()
{
    int mat[][MAX] = { { 1, 3, 5 },
                       { 3, 2, 4 },
                       { 5, 4, 1 } };
  
    if (isSymmetric(mat, 3))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS