T. *_*ima 0 c parameters matrix
我正在尝试进行Cramer线性求解,我编写了一个替换矩阵列的函数,就像这样:
void replacecol(int c, int n, float mat_in[n][n], float vect_in[n],
float mat_out[n][n])
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (j == c)
{
mat_out[i][j] = vect_in[j];
}
else
{
mat_out[i][j] = mat_in[i][j];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它目前是无效的,我希望它返回mat_out的值,当我调用这个函数时......我怎么能这样做?
您可以避免为您的功能使用2个矩阵.你可以简单地说:
void replacecol(int c, int n, float mat_in[n][n], float vect_in[n]))
{
int i;
for (i = 0; i < n; i++)
{
mat_in[i][c] = vect_in[i];
}
}
Run Code Online (Sandbox Code Playgroud)
float mat_in[n][c]它是一个指针,float(*)[]因此对传递的矩阵进行对该参数的修改.