资源描述:
《高斯列主元消元法的vc语言代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、【这是自己编写的程序,请自己阅读着使用。】/*shuzhi1*/#include#defineC3voidmain(){floatA[C][C];floatb[C];floatX[C];floatt,r,s;inti,j,k,m,n;printf("PleaseinputA:");for(i=0;i<=C-1;i++){for(j=0;j<=C-1;j++)scanf("%f",&A[i][j]);}printf("Thedatainthecomputeris:A=");for(i=0
2、;i<=C-1;i++){for(j=0;j<=C-1;j++)printf("%4.4f",A[i][j]);printf("");}/*A数据的输入与检验*/printf("Isthereanymistake?Press1foryes,Press0forno!");scanf("%d",&k);for(;k==1;){printf("Pleaseinputtheadress(i,j)oftheerrordata:");scanf("%d",&i);scanf("%d",&j);printf("Pleasei
3、nputtherightdata:");scanf("%f",&t);A[i-1][j-1]=t;printf("Thedatainthecomputeris:A=");for(i=0;i<=C-1;i++){for(j=0;j<=C-1;j++)printf("%4.4f",A[i][j]);printf("");}printf("Isthereanymistake?Press1foryes,Press0forno!");scanf("%d",&k);}/*修改出错数据*/printf("Please
4、inputb:");for(i=0;i<=C-1;i++)scanf("%f",&b[i]);printf("Thedatainthecomputeris:b=");for(i=0;i<=C-1;i++)printf("%4.4f",b[i]);/*b数据的输入与检验*/printf("Isthereanymistake?Press1foryes,Press0forno!");scanf("%d",&k);for(;k==1;){printf("Pleaseinputtheadress(i)ofth
5、eerrordata:");scanf("%d",&i);printf("Pleaseinputtherightdata:");scanf("%f",&t);b[i-1]=t;for(i=0;i<=C-1;i++)printf("%4.4f",b[i]);printf("Isthereanymistake?Press1foryes,Press0forno!");scanf("%d",&k);}/*修改出错数据*//*选择主元*/for(i=0;i<=C-2;i++){for(j=i+1;j<=C-1;j++){
6、if(A[i][i]<=0)r=-A[i][i];elser=A[i][i];if(A[j][i]<=0)s=-A[j][i];elses=A[j][i];if(r
7、1;m++){for(n=0;n<=C-1;n++)printf("%4.4f",A[m][n]);printf("b[%d]=%4.4f",m+1,b[m]);printf("");}printf("");/*打印变化后的数组*/for(m=i+1;m<=C-1;m++){t=(-A[m][i]);for(n=0;n<=C-1;n++)A[m][n]=A[m][n]+(A[i][n]/A[i][i])*t;b[m]=b[m]+b[i]/A[i][i]*t;}for(m=0;m<=C-1;m++){for(
8、n=0;n<=C-1;n++)printf("%4.4f",A[m][n]);printf("b[%d]=%4.4f",m+1,b[m]);printf("");}printf("");}/*主元消零并打印当前数组*//*迭代求X[C]*/for(i=0;i<=C-1;i++)X[i]=0;for(i=C-1;i>=0;i--){t=0;for(j=