It's been a long time since I wrote C, and today I wrote a matrix algorithm.
The complete code is as follows:
#include <atlstr.h>#include<iostream>#include<string>using namespacestd;//Create a matrixfloat**creat (intN) { float**array=New float*[n]; for(intI=0; i<n;i++) {Array[i]=New float[n]; } printf ("Please enter the matrix: \ n"); for(intI=0; i<n;i++) { for(intj=0; j<n;j++) {cin>>Array[i][j]; } } returnArray;}//to find the determinant value:floatValue (float**array,intN) { floatresult=0; if(n==1)returnarray[0][0]; float**temp=New float*[n-1]; for(intI=0; i<n-1; i++) {Temp[i]=New float[N-1]; } for(intI=0; i<n;i++) { for(intj=0; j<n-1; j + +) { for(intk=0; k<n-1; k++) { intFlag; if(j<i) flag=0; Elseflag=1; TEMP[J][K]=array[j+flag][k+1]; } } intflag2=-1; if(i%2==0) flag2=1; Result+=flag2*array[i][0]*value (temp,n-1); } returnResult;}//Inverse matrix: The value of the determinant of the adjoint matrix divided by the determinantfloat**getmarin (float**array,intN) { float**resultmarin=Array; floatresultsum=Value (array,n); float**temp=New float*[n-1]; for(intI=0; i<n-1; i++) {Temp[i]=New float[N-1]; } for(intI=0; i<n;i++) { for(intj=0; j<n;j++) { for(intk=0; k<n-1; k++) { for(intm=0; m<n-1; m++) { intflag1=0; intFlag2=0; if(k<i) flag1=0; Elseflag1=1; if(M<J) flag2=0; ElseFlag2=1; TEMP[K][M]=array[k+flag1][m+Flag2]; } } intflag3=-1; if((i+j)%2==0) flag3=1; Resultmarin[j][i]=(float) Flag3*value (temp,n-1)/resultsum; } } returnResultmarin;}voidOutPut (float**array,intN) {printf ("inverse matrix: \ n"); for(intI=0; i<n;i++) { for(intj=0; j<n;j++) {printf ("%f", Array[i][j]); } printf ("\ n"); }}voidTest () {printf ("Please enter the order of the Matrix you want to enter:"); intN; CIN>>N; float**array=creat (n); floatresult=Value (array,n); printf ("determinant Value =%f\n", Result); if(result==0) printf ("The matrix has no inverse matrix \ n"); Else { float**resultmarin=Getmarin (array,n); OutPut (Resultmarin,n); } Test ();}voidMain () {Test ();}
Operation Result:
The inverse matrix of matrices and the recursive algorithm of determinant values.