【发布时间】:2013-12-31 10:33:39
【问题描述】:
所以我编写了下面的代码作为求解二维线性方程组的程序。
#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 中使用布尔值的内容,但我不明白如何或为什么将其实现为行列式函数。
【问题讨论】:
-
我相信我们将使用布尔返回值来确定是否实际计算了解决方案。所以是的,对于非零行列式,它应该返回 true,对于零行列式,它应该返回 false。
-
“行列式”是根据 2x2(不是 2x3)矩阵计算得出的。解是根据 2x3 矩阵计算得出的。