这道题就是算个行列式然后mod一个数
#include
#include
#include
void getarray(int n);
void showarray(int n);
double getresult(int n);
double array[102][102];
int main()
{int n,m,k;
double result;
scanf("%d%d",&n,&m);
getarray(n);
showarray(n);
result=getresult(n);
k=(int)result%m;
if(k<0)k+=m;
printf("%ld\n",k);
system("pause");
return 0;
}
void getarray(int n)
{int row,col;
for(row=0;row<n;row++)
{for(col=0;col<n;col++)
scanf("%lf",&array[row][col]);
}
}
void showarray(int n)
{int row,col;}
double getresult(int n)
{double temp,result=1.0;
int switchtime=0,flag=0;
int row,nextrow,col,stemp;
for(row=0;row<n-1;row++)
{nextrow=row+1;
if(array[row][row]==0)
{while(array[nextrow][row]==0)
{nextrow++;
if(nextrow==n){flag=1;break;}
}
if(flag==1) continue;
switchtime++;
for(col=0;col<n;col++)
{stemp=array[row][col];
array[row][col]=array[nextrow][col];
array[nextrow][col]=stemp;
}
}
for(nextrow=row+1;nextrow<n;nextrow++)
{temp=array[nextrow][row]/array[row][row];
for(col=0;col<n;col++)
array[nextrow][col]+=-temp*array[row][col];
}
}
showarray(n);
for(row=0;row<n;row++)
result*=array[row][row];
if(switchtime%2) return -result;
else return result;
}
我的程序大家帮忙看下错误,谢谢了
|