Problem Statement
Write a c program to check whether the given two matrix is identical or not.
- This is a c program to check whether the given matrices are identical or not. Here variables n, m are rows and columns.
- If they are not equal then the matrix is not going to be identical so program gets stopped there.
- If n and m values are equal then the c program accepts input of two matrix to check for identical matrix.
- Thereafter using nested for loop we are checking the two matrices for identical. If anyone of the condition fails to satisfy the if condition in nested for loop then the program will print the output as matrix is not identical.
- In Nested for loop all if condition are satisfied then the program will print the output as The Matrix is identical.
Solution
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,m,i,j;
scanf("%d%d",&n,&m);
if(n!=m)
{
printf("\nTHE MATRIX IS NOT IDENTICAL");
return 0;
}
int a[n][m],b[n][m];
printf("\n First Matrix");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
scanf("\n");
}
printf("\n Second Matrix");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&b[i][j]);
}
scanf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=b[i][j])
{
printf("\nTHE MATRIX IS NOT IDENTICAL");
return 0;
}
}
}
printf("\nTHE MATRIX IS IDENTICAL");
return 0;
}
Input
3 3
First Matrix
1 2 3
4 5 6
7 8 9
Second Matrix
1 2 3
4 5 6
7 8 9