1 #include2 #include 3 using namespace std; 4 #define maxn 50 5 int n;//维数 6 double a[maxn][maxn];//系数矩阵 7 double b[maxn];//b向量 8 double kc=0.000001;//精度控制常数 9 double x[maxn];//x向量10 double y[maxn];11 double e;12 int N0;//最大迭代次数13 //e=||x-(k+1)-x(k)||.inf.;当e >n;20 cout<<" 请输入系数矩阵a:="\n";21" for(i="1;i<=n;i++)//输入a[][]22" for(j="1;j<=n;j++)23" cin> >a[i][j];24 cout<<"请输入b向量b:= \n";25 for(i=1;i<=n;i++)cin>>b[i];//输入b[]26 cout<<"请输入x向量的初始值x:= \n";27 for(i=1;i<=n;i++)cin>>x[i];//输入x[]初始值28 cout<<"请输入估计最大迭代次数N0:= \n";29 cin>>N0;30 return 1;31 }32 int main(){33 while(read()){34 for(k=1;k<=N0;k++){35 e=-1;36 for(i=1;i<=n;i++){37 y[i]=b[i];38 for(j=1;j<=n;j++)if(i!=j){39 y[i]-=a[i][j]*x[j];40 }41 y[i]/=a[i][i];42 if(fabs(x[i]-y[i])>e)e=fabs(x[i]-y[i]); 43 }if(e