Today, using array pointers to rewrite the determinant of the program, Code:
1#include <iostream>2#include <cmath>3 using namespacestd;4 intMain ()5 {6 intrank;7 voidSetdet (Double*,int);8 DoubleValdet (Double*,int);9cout<<"Enter the order of the determinant:";TenCin>>rank; One Double*detptr=New Double[rank*rank]; A Setdet (Detptr,rank); -cout<<"the determinant values are:"<<valdet (Detptr,rank) <<Endl; - return 0; the } - voidSetdet (Double*detptr,intrank) - { -cout<<"input determinant:"<<Endl; + intm=rank*rank; - for(intI=0; i<m;i++) +Cin>>Detptr[i]; A } at DoubleValdet (Double* Detptr,intrank) - { - DoubleVal=0; - if(rank==1)returndetptr[0]; - for(intI=0; i<rank;i++)//calculation cofactor saved in nextdetptr[] - { in Double*nextdetptr=New Double[(rank-1) * (rank-1)]; - for(intj=0; j<rank-1; j + +) to for(intk=0; k<i;k++) +nextdetptr[j* (rank-1) +k]=detptr[(j+1) *rank+K]; - for(intj=0; j<rank-1; j + +) the for(intk=i;k<rank-1; k++) *nextdetptr[j* (rank-1) +k]=detptr[(j+1) *rank+k+1]; $Val+=detptr[i]*valdet (nextdetptr,rank-1) *pow (-1.0, i);Panax Notoginseng } - returnVal; the}
Using recursion and determinant expansion theorem to find the value of determinant (array pointer version)