Program to determine whether two matrices are equal
In this program, we need to check whether given matrices are equal or not.
Two matrices are said to be equal if and only if they satisfy the following conditions:
- Both the matrices should have the same number of rows and columns.
- Both the matrices should have the same corresponding elements.
Consider the above example, where matrices A and B are equal as they have the same size and same corresponding elements.
- Declare and initialize two two-dimensional arrays a and b.
- Calculate the number of rows and columns present in the array a and store it in variables row1 and col1 respectively.
- Calculate the number of rows and columns present in array b and store it in variables row2 and col2 respectively.
- Initialize variable flag to true.
- Check if the size of both the arrays is equal. If arrays are not of equal size then, display the message " Matrices are not equal".
- If the size of both the arrays is equal then, loop through both the arrays and compare each element.
- If any of the corresponding elements are not equal then, set the flag to false and break the loop.
- If the flag is equal to true which implies matrices are equal. Else, matrices are not equal.