我不确定自己出了什么问题,我的代码似乎与单个整数旁边的其他任何东西无关。我试图得到3x3数组并找到它的行列式并计算出它的反函数,然后进行乘法得到我。
//matrix product
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 3; k++) {
product[i][j] += array[i][k] * invertA[k][j];
}
}
}
...下面是用户输入的数组
int main() {
int array[3][3], invertA[3][3], product[3][3], i, j, k; // The global scope
// ask for input
printf("Please enter 9 elements of the matrix seperated by a space: \n");
for (i = 0; i < 3; i++) { //the loop - create a table of 3 x 3
for (j = 0; j < 3; j++) {
scanf("%d", &array[i][j]); //save user-input as integer (%d) into the matrix a[i][j]
}
}
,另一个数组来自代码
//a11 a12 a13
invertA[0][0] = (array[1][1] * array[2][2] - array[2][1] * array[1][2]) / determinant;
invertA[0][1] = -(array[1][0] * array[2][2] - array[1][2] * array[2][0]) / determinant;
invertA[0][2] = (array[1][0] * array[2][1] - array[2][0] * array[1][1]) / determinant;
//a21 a22 a23
invertA[1][0] = -(array[0][1] * array[2][2] - array[0][2] * array[2][1]) / determinant;
invertA[1][1] = (array[0][0] * array[2][2] - array[0][2] * array[2][0]) / determinant;
invertA[1][2] = -(array[0][0] * array[2][1] - array[2][0] * array[0][1]) / determinant;
//a31 a32 a33
invertA[2][0] = (array[0][1] * array[1][2] - array[0][2] * array[1][1]) / determinant;
invertA[2][1] = -(array[0][0] * array[1][2] - array[1][0] * array[0][2]) / determinant;
invertA[2][2] = (array[0][0] * array[1][1] - array[1][0] * array[0][1]) / determinant;