用Gauss-Seidel 迭代法解线性方程组的 C 语言源代码: #include #include #include struct Line{ int L; struct Row *head; struct Line *next; } ; struct Row{ int R; float x; struct Row *link; } ; //建立每次迭代结果的数据存储单元 struct Term{ float x; float m; } ; struct Line *Create(int Line,int Row){ struct Line *Lhead=NULL,*p1=NULL,*p2=NULL; struct Row*Rhead=NULL,*ptr1,*ptr2=NULL; int i=1,j=1; float X; while(i<=Line){ while(j<=Row+1){ scanf("%f",&X); if(X!=0||j==Row+1){ ptr1=(struct Row*)malloc(sizeof(Row)); if(ptr1==NULL){ printf("内存分配错误!\n"); exit(1); } ptr1->x=X; ptr1->R=j; if(ptr2==NULL){ ptr2=ptr1; Rhead=ptr1; } else{ ptr2->link=ptr1; ptr2=ptr1; } } j++; } if(ptr2!=NULL){ ptr2->link=NULL; ptr2=NULL; } if(Rhead!=NULL){ p1=(struct Line*)malloc(sizeof(Line)); if(p1==NULL){ printf("内存分配错误!\n"); exit(1); } p1->L=i; p1->head=Rhead; if(p2==NULL){ Lhead=p1; p2=p1; } else{ p2->next=p1; p2=p1; } } i++; Rhead=NULL; j=1; } if(p2!=NULL) p2->next=NULL; return Lhead; } struct Line *Change(struct Line*Lhead,int n){ struct Line*p1,*p2,*p3,*p; struct Row*ptr; int i=1,k,j; float max,t; if(Lhead==NULL){ printf("链表为空!\n"); exit(1); } p2=Lhead; while(i<=n){ max=0; k=0; t=0; ptr=p2->head; while(ptr!=NULL){ if(ptr->R!=n+1){ t+=fabs(ptr->x); if(maxx)){ max=fabs(ptr->x); k=ptr->R; } } ptr=ptr->link; } t=t-max; if(max<=t){ printf("系数矩阵A 不具有严格对角优势,该程序不能用 Gauss-Jacobi 迭代法解该方程组!\n"); return NULL; } if(p2->L==k) p2=p2->next; else if(p2->L>k){ printf("系数矩阵A 不具有严格对角优势,该程序不能用 Gauss-Jacobi 迭代法解该方程组!\n"); exit(0); } else{ p3=Lhead; while(p3->L!=k) p3=p3->next; ptr=p3->head; p3->head=p2->head; p2->head=ptr; } i++; } return Lhead; } void Deal(struct Line *Lhead,float e,int N,int n){ struct Term*ptr; struct Line*p1...