求矩阵的逆矩阵c语言编的程序

2021-11-04 教育 254阅读
#defineN5
#include"stdio.h"
#include"conio.h"


intjs(s,n)
ints[][N],n;
{intz,j,k,r,total=0;
intb[N][N];
if(n>2){for(z=0;z{for(j=0;jfor(k=0;kif(k>=z)b[j][k]=s[j+1][k+1];
elseb[j][k]=s[j+1][k];
if(z%2==0)r=s[0][z]*js(b,n-1);
elser=(-1)*s[0][z]*js(b,n-1);
total=total+r;
}
}
elseif(n==2)total=s[0][0]*s[1][1]-s[0][1]*s[1][0];
returntotal;
}


voidn_1(s,b,n)
ints[][N],n;
floatb[][N];
{intz,j,k,l,m,g,a[N][N];
for(z=0;z{l=z;
for(j=0;j{m=j;
for(k=0;kfor(g=0;g{if(g>=m&&kelseif(k>=l&&gelseif(k>=l&&g>=m)a[k][g]=s[k+1][g+1];
elsea[k][g]=s[k][g];
}
b[z][j]=js(a,n-1);
}
}
}

main()
{inta[N][N];
floatb[N][N];
intr,z,j;
floattemp;
//clrscr();
printf("Inputoriginaldata:\n");
for(z=0;zfor(j=0;jscanf("%d",&a[z][j]);
printf("\nPressEntercontinue......");
getchar();
//gotoxy(1,1);
printf("Theoriginalmatrixis:\n");
for(z=0;z{for(j=0;jprintf("%5d",a[z][j]);
printf("\n");
}
r=js(a,N);
printf("\nTheoriginalmatrixhanglieshiis:|A|==%d\n",r);
if(r==0)printf("Because|A|==0,theoriginalmatrixhavenonijuzhen!");
else
{n_1(a,b,N);
for(z=0;zfor(j=0;jif((z+j)%2!=0&&b[z][j]!=0)b[z][j]=-b[z][j];
for(z=0;zfor(j=z+2;j{temp=b[z][j];
b[z][j]=b[j][z];
b[j][z]=temp;
}
printf("Because|A|!=0,theoriginalmatrixhavenijuzhen!\n");
printf("ThebansuijuzhenA*is:\n");
for(z=0;z{for(j=0;jprintf("%4.0f\t",b[z][j]);
printf("\n");
}

for(z=0;zfor(j=0;jb[z][j]=b[z][j]/r;
printf("\nThenijuzhenis:(A*)/|A|(|A|=%d)\n",r);
for(z=0;z{for(j=0;jprintf("%8.3f",b[z][j]);
printf("\n");
}
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com