顺序消元法:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int n=4;//定义矩阵的维数
int i,j,k;//i为矩阵的行,j为矩阵的列,k为消元次数
double m,temp;//m为高斯消元中的系数,temp为交换时的中间变量
double sum=0;//回代过程中求和
double a[4][4]={ {1.1348,3.8326,1.1651,3.4017},{0.5301,1.7875,2.5330,1.5435},{3.4129,4.9317,8.7643,1.3142},{1.2371,4.9998,10.6721,0.0147}};//系数矩阵
double b[4][1]={9.5342,6.3941,18.4231,16.9237};//
double x[4][1]={0.0000,0.0000,0.0000,0.0000};//解向量
//高斯消元
for(k=0;k<n;k++)
{
if(fabs(a[k][k]==0))//若约化主元为0,则找一列不为0的与其交换
{
for(i=k+1;i<n;i++)
{
if(fabs(a[i][k]!=0))//若第k行满足该条件,则将第k行与第i行进行交换
{
temp=b[k][0];
b[k][0]=b[i][0];
b[i][0]=temp;
for(j=i-1;