问题
I'm trying to make a Cramer-linear-solving, and I wrote a function that replaces a matrix column, just like that:
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];
}
}
}
}
But it is currently void, and I want it to return the mat_out with it's values, when I call this function... How could I do that??
回答1:
You can avoid to use 2 matrices for your function. You can simply:
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];
}
}
float mat_in[n][c] it is a pointer float(*)[] so modifications on that parameter are made on the passed matrix.
来源:https://stackoverflow.com/questions/42368262/how-to-return-matrix