判断输入的矩阵是否是单位矩阵
#include<iostream>
using namespace std;
#define N 3
bool judge(int(*arr)[10])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (i == j && arr[i][j] != 1)
{
return false;
}
if (i != j && arr[i][j] != 0)
{
return false;
}
}
return true;
}
}
int main()
{
int arr[10][10];
for (int i = 0; i < N; i++)
{
cout << "请输入第" << i << "行的数字" << endl;
for (int j = 0; j < N; j++)
{
cin >> arr[i][j];
}
}
if (judge(arr))
{
cout << "是单位矩阵" << endl;
}
else
{
cout << "不是单位矩阵" << endl;
}
system("pause");
}