Principle:
First row of the largest element of the first column is placed on the first line (on the first main element), with the largest element of the first column of the other elements into 0;
Compare the first element to zero the second element of the row, Repeat the above steps by placing the large in the first line except the first line (that is, after the first row (transformed) is transparent and no longer participates in the operation). The
is finally brought back to solve.
#include "stdafx.h" #include "stdio.h" #include "math.h" int main () {double m,p,a[10][10],x[10];
int n,i,j,k,q;
char c; printf ("Please enter the order of the equation (less than or equal to 8): \ n");
8 is because (1) rows and columns are both starting from 1 (2) and the constant number scanf ("%d", &n) on the right side;
Enter the augmented matrix for (i=1;i<=n;i++)//from a[1][1] to deposit data {printf ("Please enter the augmented matrix%d line: \ n", i);
for (j=1;j<=n+1;j++) scanf ("%lf", &a[i][j]); }//For (i=1;i<n;i++) {m=fabs (a[i][i]); j=i; m represents the maximum value in the remaining column I, J is used to mark the maximum number of rows for (k=i+1;k<=n;k++) {if (Fabs (A[k][i]) >m) {M=fabs (a[k][i
]); j=k;}
}//Exchange line, put the largest J row in each need to eliminate the first line for (q=i;q<=n+1;q++) {p=a[i][q];
A[I][Q]=A[J][Q];
A[j][q]=p; }//Eliminate the process for (k=i+1;k<=n;k++) {m=-a[k][i]/a[i][i];//to zero the column except for the largest element of the element into zeros for (j=i;j<
; =n+1;j++) A[k][j]=a[k][j]+a[i][j]*m;
}}//****** return process ****** x[n]=a[n][n+1]/a[n][n]; for (i=n-1;i>=1;i--) {p=0.0;
for (j=i+1;j<=n;j++) p=p+a[i][j]*x[j];
x[i]= (a[i][n+1]-p)/a[i][i];
}//for printf ("The solution of a linear equation group is: \ n");
for (i=1;i<=n;i++) printf ("x[%d]=%.3lf\n", I,x[i]);
C=getchar ();
return 0;
}