Answer to Question #228756 in C++ for Karthi

Question #228756
Write a C++ program to check if 2 matrices are same b overloading == operator.
Two matrices A and B are said to be same if Aij = Bij for 0<=i,j<=n-1.
1
Expert's answer
2021-08-23T18:32:41-0400
#include <iostream>
#define N 4
using namespace std;
 
int sameMatrics(int A[][N], int B[][N])
{
    
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if (A[i][j] != B[i][j])
                return 0;
    return 1;
}
 
int main()
{
    int A[N][N] = { {1, 2, 3, 4},
                    {5, 6, 7, 8},
                    {9, 10, 11, 12},
                    {13, 14, 15, 16}};
 
    int B[N][N] = { {1, 2, 3, 4},
                    {5, 6, 7, 8},
                    {9, 10, 11, 12},
                    {13, 14, 15, 16}};
 
    if (sameMatrics(A, B))
        cout << "Matrices are same";
    else
        cout << "Matrices are not same";
    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