C Exercises: Accept two matrices and check whether they are equal
30. Matrix Equality Check
Write a program in C to accept two matrices and check whether they are equal.
The task is to write a C program that accepts two matrices and checks if they are equal. The program prompts the user to input the dimensions and elements of both matrices, then compares corresponding elements. If all elements are identical, the program will confirm that the matrices are equal.
Visual Presentation:

Sample Solution:
C Code:
Sample Output:
Accept two matrices and check whether they are equal : ----------------------------------------------------------- Input Rows and Columns of the 1st matrix :2 2 Input Rows and Columns of the 2nd matrix :2 2 Input elements in the first matrix : element - [0],[0] : 1 element - [0],[1] : 2 element - [1],[0] : 3 element - [1],[1] : 4 Input elements in the second matrix : element - [0],[0] : 1 element - [0],[1] : 2 element - [1],[0] : 3 element - [1],[1] : 4 The first matrix is : 1 2 3 4 The second matrix is : 1 2 3 4 The Matrices can be compared : Two matrices are equal.
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to compare two matrices element-wise and output the differing elements.
- Write a C program to check if two matrices are equal using pointer arithmetic.
- Write a C program to accept two matrices and then verify equality using recursion.
- Write a C program to compare two matrices and display a message for each row indicating if they are equal.
C Programming Code Editor:
Previous: Write a program in C to accept a matrix and determine whether it is a sparse matrix.
Next: Write a program in C to check whether a given matrix is an identity matrix.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.