所以我將下面的代碼寫成程序來解決二維線性方程組。從2x3陣列矩陣計算行列式
#include <stdio.h>
int main()
{
int eq[2][3];
int D, Dx, Dy;
int sol[2];
printf("Enter cofficients of first equation: ");
scanf("%d %d %d", &eq[0][0], &eq[0][1], &eq[0][2]);
printf("Enter cofficients of second equation: ");
scanf("%d %d %d", &eq[1][0], &eq[1][1], &eq[1][2]);
D = eq[0][0]*eq[1][1] - eq[1][0]*eq[0][1];
Dx = eq[0][2]*eq[1][1] - eq[1][2]*eq[0][1];
Dy = eq[0][0]*eq[1][2] - eq[1][0]*eq[0][2];
if(D != 0){
sol[0] = Dx/D; // x solution
sol[1] = Dy/D; // y solution
printf("x = %d, y = %d \n", sol[0], sol[1]);
}
else{
printf("No unique solutions exist. \n");
}
return 0;
}
我現在已經被委託使用原型轉換到這個函數:
bool determinantFunction(int e[][3], int s[]);
我的問題是,我不知道從哪裏開始。我已經閱讀了儘可能多地在C中使用布爾值的方法,但我不明白如何或爲什麼要將它用於實現一個行列式函數。
我相信我們將使用布爾返回值來確定解決方案是否實際計算。所以是的,它應該對非零行列式返回正確,對於零行列式應該返回錯誤。 – Ben
「行列式」是從2×2(不是2×3)矩陣計算而來的。解決方案從2x3矩陣計算。 – chux