题解 | #矩阵相等判定#
矩阵相等判定
https://www.nowcoder.com/practice/2f058b1e89ae43f7ab650c0fd0b71fa8
#include <stdio.h> /* 判断两个同型矩阵是否相等 参数表:arr1矩阵1 arr2矩阵2 n行数 m列数 返回值:1相等 0不相等 */ int IsMatricesEqual(const int arr1[10][10], const int arr2[10][10], const unsigned int n, const unsigned int m) { for(int i = 0; i < n; i++) { for(int j = 0; j<m; j++) { if(arr1[i][j] != arr2[i][j]) { return 0; } } } return 1; } int main() { int arr1[10][10] = { 0 }; int arr2[10][10] = { 0 }; //输入行数和列数 unsigned int n = 0; unsigned int m = 0; scanf("%d %d", &n, &m); //依次输入两个矩阵 for(int i = 0; i<n; i++) { for(int j = 0; j<m; j++) { scanf("%d", &arr1[i][j]); } } for(int i = 0; i<n; i++) { for(int j = 0; j<m; j++) { scanf("%d", &arr2[i][j]); } } //判断arr1和arr2是否相等,并输出相关提示 if(IsMatricesEqual(arr1, arr2, n, m)) { printf("Yes\n"); } else { printf("No\n"); } return 0; }