这是矩阵行列式的 C 代码,但它给出了编译错误。
代码是:
#include<stdio.h>
#include<math.h>
int m;
float determinant(float b[][]);
int main(void)
{
int i,j,m;
printf("enter a no: ");
scanf("%d",&m);
//printf("%d",m);
float arr[m][m];
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
scanf("%f",&arr[i][j]);
//printf("%f",arr[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf("%f ",arr[i][j]);
}
printf("\n");
}
float det = determinant(arr);
printf("Determinant= %f ", det);
}
float determinant(float b[][])
{
int i,j;
int p;
float sum = 0;
float c[m][m];
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf("%f ",b[i][j]);
}
printf("\n");
}
if(m==2)
{
printf("Determinant for m=2");
sum = b[0][0]*b[1][1] - b[0][1]*b[1][0];
return sum;
}
for(p=0;p<m;p++)
{
int h = 0,k = 0;
for(i=1;i<m;i++)
{
for( j=0;j<m;j++)
{
if(j==p)
continue;
c[h][k] = b[i][j];
k++;
if(k == m-1)
{
h++;
k = 0;
}
}
}
m=m-1;
sum = sum + b[0][p]*pow(-1,p) * determinant(c);
}
return sum;
}
编译错误是:
det.c:5:25: error: array type has incomplete element type
det.c: In function ‘main’:
det.c:36:2: error: type of formal parameter 1 is incomplete
det.c: At top level:
det.c:45:25: error: array type has incomplete element type
det.c: In function ‘determinant’:
det.c:91:3: error: type of formal parameter 1 is incomplete
det.c:99: confused by earlier errors, bailing out
Preprocessed source stored into /tmp/cc1Kp9KD.out file, please attach this to your bug report.
我认为错误在于二维数组的传递。当我将它作为指针传递时,它会给出警告但没有错误,但它不会给出正确的结果,因为总是将行列式设为零。所以我猜这个数组并没有被传递,当我在函数行列式中打印它时它也不会打印。请帮忙,因为我在我的项目中被困住了。