Untitled
unknown
plain_text
2 years ago
1.4 kB
7
Indexable
#include <stdio.h>
int main() {
int r1, c1, r2, c2;
int matrix1[10][10], matrix2[10][10];
int i, j;
int identical = 1; // Assume matrices are identical initially
printf("Enter the number of rows and columns for matrix1 (r1 c1):\n");
scanf("%d %d", &r1, &c1);
printf("Enter elements of matrix1:\n");
for (i = 0; i < r1; i++) {
for (j = 0; j < c1; j++) {
scanf("%d", &matrix1[i][j]);
}
}
printf("Enter the number of rows and columns for matrix2 (r2 c2):\n");
scanf("%d %d", &r2, &c2);
if (r1 != r2 || c1 != c2) {
printf("Matrices are not identical.\n");
return 0;
}
printf("Enter elements of matrix2:\n");
for (i = 0; i < r2; i++) {
for (j = 0; j < c2; j++) {
scanf("%d", &matrix2[i][j]);
}
}
// Check if matrices are identical
for (i = 0; i < r1; i++) {
for (j = 0; j < c1; j++) {
if (matrix1[i][j] != matrix2[i][j]) {
identical = 0; // Matrices are not identical
break;
}
}
if (!identical) {
break;
}
}
if (identical) {
printf("Matrices are identical.\n");
} else {
printf("Matrices are not identical.\n");
}
return 0;
}
Editor is loading...
Leave a Comment