js()函数用于计算行列式,通过递归算法实现出错 请高手指导
#defineN5/*[注]:修改6为你所要的矩阵阶数*/#include"stdio.h"#include"conio.h"#include"math.h"/*js()...
#define N 5 /*[注]:修改6为你所要的矩阵阶数*/
#include "stdio.h"
#include "conio.h"
#include "math.h"
/*js()函数用于计算行列式,通过递归算法实现*/
int js(s,n)
int s[][N],n;
{int z,j,k,r,total=0;
int b[N][N]; /*b[N][N]用于存放,在矩阵s[N][N]中元素s[0]的余子式*/
if(n>2) {for(z=0;z<n;z++)
{for(j=0;j<n-1;j++)
for(k=0;k<n-1;k++)
if(k>=z) b[j][k]=s[j+1][k+1];
else b[j][k]=s[j+1][k];
if(z%2==0) r=s[0][z]*js(b,n-1); /*递归调用*/
else r=(-1)*s[0][z]*js(b,n-1);
total=total+r;
}
}
else if(n==2) total=s[0][0]*s[1][1]-s[0][1]*s[1][0];
return total;
}
运行时出错:error C2065: 's' : undeclared identifier
F:\work1\js\js.cpp(6) : error C2065: 'n' : undeclared identifier
F:\work1\js\js.cpp(7) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
F:\work1\js\js.cpp(7) : fatal error C1004: unexpected end of file found 展开
#include "stdio.h"
#include "conio.h"
#include "math.h"
/*js()函数用于计算行列式,通过递归算法实现*/
int js(s,n)
int s[][N],n;
{int z,j,k,r,total=0;
int b[N][N]; /*b[N][N]用于存放,在矩阵s[N][N]中元素s[0]的余子式*/
if(n>2) {for(z=0;z<n;z++)
{for(j=0;j<n-1;j++)
for(k=0;k<n-1;k++)
if(k>=z) b[j][k]=s[j+1][k+1];
else b[j][k]=s[j+1][k];
if(z%2==0) r=s[0][z]*js(b,n-1); /*递归调用*/
else r=(-1)*s[0][z]*js(b,n-1);
total=total+r;
}
}
else if(n==2) total=s[0][0]*s[1][1]-s[0][1]*s[1][0];
return total;
}
运行时出错:error C2065: 's' : undeclared identifier
F:\work1\js\js.cpp(6) : error C2065: 'n' : undeclared identifier
F:\work1\js\js.cpp(7) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
F:\work1\js\js.cpp(7) : fatal error C1004: unexpected end of file found 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询