Click here to Skip to main content
15,900,254 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
#include<stdio.h>
#include<math.h>
float detrm(float[][],float);
void cofact(float[][],float);
void trans(float[][],float[][],float);
main()
{
	float a[25][25],k,d;
	int i,j;
	printf("ENTER THE ORDER OF THE MATRIX:\n");
	scanf("%f",&k);
	printf("ENTER THE ELEMENTS OF THE MATRIX:\n");
	for(i=0;i<k;i++)
	{
		for(j=0;j<k;j++)
		{
			scanf("%f",&a[i][j]);
		}
	}
	d=detrm(a,k);
	printf("THE DETERMINANT IS=%f",d);
	if(d==0)
	printf("\nMATRIX IS NOT INVERSIBLE\n");
	else
	cofact(a,k);
}
/******************FUNCTION TO FIND THE DETERMINANT OF THE MATRIX************************/
 
float detrm(float a[25][25],float k)
{
	float s=1,det=0,b[25][25];
	int i,j,m,n,c;
	if(k==1)
	{
		return(a[0][0]);
	} 
	else
	{
		det=0;
		for(c=0;c<k;c++)
		{
			m=0;
			n=0;	
			for(i=0;i<k;i++)
			{
				for(j=0;j<k;j++)
				{
					b[i][j]=0;
					if(i!=0&&j!=c)
					{
						b[m][n]=a[i][j];
						if(n<(k-2))
							n++;
						else
						{	
							n=0;
							m++;
						}
					}
				}
			}
			det=det+s*(a[0][c]*detrm(b,k-1));
			s=-1*s;
		}
	}
	return(det);
}
 
/*******************FUNCTION TO FIND COFACTOR*********************************/ 
 
void cofact(float num[25][25],float f){ 
float b[25][25],fac[25][25]; 
int p,q,m,n,i,j; 
for(q=0;q<f;q++){
for(p=0;p<f;p++){
m=0;
n=0;
for(i=0;i<f;i++){
for(j=0;j<f;j++){
b[i][j]=0;
if(i!=q&&j!=p)
{
b[m][n]=num[i][j];
if(n<(f-2))
n++;
else{
n=0;
m++;
}
}
}
}
fac[q][p]=pow(-1,q+p)*detrm(b,f-1);
}
}
trans(num,fac,f);
}
 
/*************FUNCTION TO FIND TRANSPOSE AND INVERSE OF A MATRIX**************************/ 
 
void trans(float num[25][25],float fac[25][25],float r){ 
int i,j;
float b[25][25],inv[25][25],d;
for(i=0;i<r;i++){
for(j=0;j<r;j++){
b[i][j]=fac[j][i];
}
}
d=detrm(num,r);
inv[i][j]=0;
for(i=0;i<r;i++){
for(j=0;j<r;j++){
inv[i][j]=b[i][j]/d;
}
}
printf("\nTHE INVERSE OF THE MATRIX:\n");
for(i=0;i<r;i++){
for(j=0;j<r;j++){
printf("\t%f",inv[i][j]);
} 
printf("\n");
} 
}

When I run this program on my computer Iam getting these errors. Please help me in debugging this. (Iam using linux operating system).
The errors are:
HTML
c:3: error: array type has incomplete element type
c:4: error: array type has incomplete element type
c:5: error: array type has incomplete element type
c:5: error: array type has incomplete element type
c: In function ‘main’:
c:20: error: type of formal parameter 1 is incomplete
c:25: error: type of formal parameter 1 is incomplete
c: In function ‘cofact’:
c:105: error: type of formal parameter 1 is incomplete
c:105: error: type of formal parameter 2 is incomplete



Thnx in advance.
Posted
Updated 8-Oct-12 5:27am
v2
Comments
Akinmade Bond 8-Oct-12 11:42am    
You need to learn about arrays in C
Sandeep Mewara 8-Oct-12 11:42am    
Did you try?

1 solution

Just take the function definitions from the top of each function and copy them to the top of your file. As it stands - you're (a) using definitions that are different to the declarations (b) you're declaring arrays of an unknown number of arrays - a no-no. The compiler can't calculate the position in memory of the start of each row if it doesn't know how long each row is.

Replace:
C++
float detrm(float[][],float);
void cofact(float[][],float);
void trans(float[][],float[][],float);


With:
C++
float detrm(float[25][25],float);
void cofact(float[25][25],float);
void trans(float[25][25],float[25][25],float);
 
Share this answer
 
Comments
N Shiva 8-Oct-12 11:46am    
Thankyou.... Now Iam getting this error....

/tmp/ccwrObJa.o: In function `cofact':
nshiva.c:(.text+0x431): undefined reference to `pow'
collect2: ld returned 1 exit status
enhzflep 8-Oct-12 11:53am    
Here you go: http://www.lmgtfy.com/?q=undefined+reference+to+%60pow%27
N Shiva 8-Oct-12 11:55am    
Sorry. I am unable to access that site from my campus.
Could you please tell me, what is the mistake.
enhzflep 8-Oct-12 12:11pm    
Mate, it's right there in the link I left you (hint: q=undefined reference to 'pow')

Throw that into google. Basically - you've included the math.h header file, but have not linked to the library that contains the functions defined in that header.

http://stackoverflow.com/questions/10167714/what-is-undefined-reference-to-pow
N Shiva 8-Oct-12 12:15pm    
THNX. I got it... I have to use cc -lm while executing...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900