这个错误不断出现,但我没有看到代码有问题(它在 c++ 中)程序应该找到 2x2 矩阵的逆矩阵
#include <iostream>
using namespace std;
int main() {
float d;
float A[2][2], B[2][2];
do {
cout << "please enter valid parameters in for 11,12,21,22" << endl;
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++)
cin >> A[i][j];
}
d = (A[1][1] * A[2][2]) - (A[1][2] * A[2][1]);
} while(d == 0);
B[1][1] = A[2][2] * (1.0 / d);
B[1][2] = A[1][2] * (-1.0 / d);
B[2][1] = A[2][1] * (-1.0 / d);
B[2][2] = A[1][1] * (1.0 / d);
for(int k = 0; k < 2; k++) {
for(int h = 0; h < 2; h++)
cout << B[k][h] << " ";
cout << endl;
}
return 0;
}