/*******************************************************作者:陈康强*时间:2013-4-10*原理:高斯消元法*适用:四元一次方程组*功能:可求解四元一次方程组,能判断是否有唯一解,*多解和唯一解,多解情况下,笔算完成!*******************************************************/#includestdio.hintmain(){floatarr[4][5],arr1[4][5];inti=0,j=0,k=0;inta=0,b=0;floatx4,x3,x2,x1;printf(请输入四元一次方程组的系数,如:3a+b+4c+2d=8,输入3回车1回车4回车2回车8回车\n);for(i=0;i4;i++)for(j=0;j5;j++){scanf(%f,&arr[i][j]);}i=0,j=0;for(j=0;j5;j++){arr1[i][j]=arr[i][j]*(arr[i+1][k]/arr[i][k]);}i=0,j=0;for(j=0;j5;j++){arr[i+1][j]=arr[i+1][j]-arr1[i][j];}i=0,j=0;for(j=0;j5;j++){arr1[i][j]=arr[i][j]*(arr[i+2][k]/arr[i][k]);}i=0,j=0;for(j=0;j5;j++){arr[i+2][j]=arr[i+2][j]-arr1[i][j];}i=0,j=0;for(j=0;j5;j++){arr1[i][j]=arr[i][j]*(arr[i+3][k]/arr[i][k]);}for(j=0;j5;j++){arr[i+3][j]=arr[i+3][j]-arr1[i][j];}i=1;j=1;k=1;for(a=1;a5;a++){arr1[i][a]=arr[i][a]*(arr[i+1][k]/arr[i][k]);}i=1;j=1;k=1;for(b=1;b5;b++){arr[i+1][b]=arr[i+1][b]-arr1[i][b];}i=1;j=1;k=1;for(a=1;a5;a++){arr1[i][a]=arr[i][a]*(arr[i+2][k]/arr[i][k]);}i=1;j=1;k=1;for(b=1;b5;b++){arr[i+2][b]=arr[i+2][b]-arr1[i][b];}i=2,j=2,k=2;for(a=2;a5;a++){arr1[i][a]=arr[i][a]*(arr[i+1][k]/arr[i][k]);}i=2,j=2,k=2;for(b=2;b5;b++){arr[i+1][b]=arr[i+1][b]-arr1[i][b];}k=0;for(i=0;i4;i++){for(j=0;j4;j++){if(arr[i][j]!=0){k++;break;}}}printf(矩阵的秩=%d\n,k);if(k4){if(arr[k-1][k]==0)printf(方程有多解\n);elseprintf(方程无解);}else{x4=arr[3][4]/arr[3][3];x3=(arr[2][4]-x4*arr[2][3])/arr[2][2];x2=(arr[1][4]-arr[1][3]*x4-arr[1][2]*x3)/arr[1][1];x1=(arr[0][4]-x4*arr[0][3]-x3*arr[0][2]-x2*arr[0][1]);printf(x4=%fx3=%fx2=%fx1=%f\n,x4,x3,x2,x1);}return0;}