在高斯消元法中假设矩阵的第一个值,A [0] [0] = 0
然后如何交换矩阵的第1行" A"第2行,这样我得到了正确的结果?
答案 0 :(得分:-1)
保持同一类型的临时值; 按价值交换价值, 例如:
temp=a[i][j];
a[i][j]=a[i+1][j];
a[i+1][j]=temp;
答案 1 :(得分:-1)
假设simpel 2d-array构建方式如下所示:只需交换行。
#include <stdio.h>
#include <stdlib.h>
#define S_MATRIX_DIM 5
int main()
{
int **A;
int *tmp;
int i, j, entry;
entry = 0;
A = malloc(S_MATRIX_DIM * sizeof(int *));
for (i = 0; i < S_MATRIX_DIM; i++) {
A[i] = malloc(S_MATRIX_DIM * sizeof(int));
for (j = 0; j < S_MATRIX_DIM; j++) {
A[i][j] = entry++;
}
}
puts("Matrix A =");
for (i = 0; i < S_MATRIX_DIM; i++) {
for (j = 0; j < S_MATRIX_DIM; j++) {
printf("%d,", A[i][j]);
}
putchar('\n');
}
tmp = A[0];
A[0] = A[1];
A[1] = tmp;
puts("Matrix A, row exchanged =");
for (i = 0; i < S_MATRIX_DIM; i++) {
for (j = 0; j < S_MATRIX_DIM; j++) {
printf("%d,", A[i][j]);
}
putchar('\n');
}
for (i = 0; i < S_MATRIX_DIM; i++) {
free(A[i]);
}
free(A);
exit(EXIT_SUCCESS);
}