C Program to accept two matrices and check if they are equal or not?. Program will accept the two matrices, and return true if their order and their elements are equal, i.e. for all , if a[i][j]==b[i][j]. Read more about C Programming Language .

/***********************************************************

* You can use all the programs on www.c-program-example.com

* for personal and learning purposes. For permissions to use the

* programs for commercial purposes,

* contact [email protected]

* To find more C programs, do visit www.c-program-example.com

* and browse!

*

* Happy Coding

***********************************************************/

/* Write a C Program to accept two matrices and check if they are equal */

#include <stdio.h>

#include <stdlib.h>

void main()

{

int A[10][10], B[10][10];

int i, j, R1, C1, R2, C2, flag =1;

printf("Enter the order of the matrix An");

scanf("%d %d", &R1, &C1);

printf("Enter the order of the matrix Bn");

scanf("%d %d", &R2,&C2);

printf("Enter the elements of matrix An");

for(i=0; i<R1; i++)

{

for(j=0; j<C1; j++)

{

scanf("%d",&A[i][j]);

}

}

printf("Enter the elements of matrix Bn");

for(i=0; i<R2; i++)

{

for(j=0; j<C2; j++)

{

scanf("%d",&B[i][j]);

}

}

printf("MATRIX A isn");

for(i=0; i<R1; i++)

{

for(j=0; j<C1; j++)

{

printf("%3d",A[i][j]);

}

printf("n");

}

printf("MATRIX B isn");

for(i=0; i<R2; i++)

{

for(j=0; j<C2; j++)

{

printf("%3d",B[i][j]);

}

printf("n");

}

/* Comparing two matrices for equality */

if(R1 == R2 && C1 == C2)

{

printf("Matrices can be comparedn");

for(i=0; i<R1; i++)

{

for(j=0; j<C2; j++)

{

if(A[i][j] != B[i][j])

{

flag = 0;

break;

}

}

}

}

else

{ printf(" Cannot be comparedn");

exit(1);

}

if(flag == 1 )

printf("Two matrices are equaln");

else

printf("But,two matrices are not equaln");

}

Read more Similar C Programs

Matrix Programs

Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com