# Determinant Prob

• 08-18-2007
dantu1985
Determinant Prob
can anyone tell me the error here....

when i press for 2*2 it works perfect...

for 3*3 it says floating point errror.....
Program to find Determinant of a Matrix

#include<stdio.h>
#include<conio.h>
#define LIMIT 10
void main()
{
int chckdgnl();
float deter();
float a[LIMIT][LIMIT],value;
int i,j,order;
clrscr();
printf("Enter order of determent :");
scanf("%d",&order);
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("Enter (%d,%d) element of the determent :",i+1,j+1);
scanf("%f",&a[i][j]);
}
}

if(chckdgnl(a,order)==0)
value=0;
else
value=deter(a,order);
printf("Determinent Value :%f",value);
getch();
}

float deter(float a[][LIMIT],int forder)
{
int i,j,k;
float mult;
float deter=1;
for(i=0;i<forder;i++)
{
for(j=0;j<forder;j++)
{
mult=a[j][i]/a[i][i];
for(k=0;k<forder;k++)
{
if(i==j) break;
a[j][k]=a[j][k]-a[i][k]*mult;
}
}
}
for(i=0;i<forder;i++)
{
deter=deter*a[i][i];
}
return(deter);
}

int chckdgnl(float array[][LIMIT],int forder)
{
int i,j,k;
float nonzero;
for(i=0;i<forder;i++)
{
if(array[i][i]==0)
{
for(j=0;j<forder;j++)
{
if(array[i][j]!=0)
{
k=j;
break;
}
if(j==(forder)) //forder-1
return(0);
}
for(j=0;j<forder;j++)
{
array[j][i]=array[j][i]-array[j][k];
}
}
}
return(1);
}
thanks
• 08-19-2007
MacGyver
1. Learn how to use code tags properly. They aren't hard to figure out, and it shows a sense of respect for us to do so. I don't feel like looking through a blob of unformatted code to spot an error you give me no real hint about. Last I heard, students don't even perform their C exams under these conditions.
2. void main() isn't standard. Use int main() and by convention, you should return 0 for success and non-zero for failure.
3. conio.h is non-portable. I suggest you get rid of it if you don't need it.

That's all I have to say for now.
• 08-19-2007
JFonseka
I compiled your code cause your code didn't look right, how did it even compile, because there are bunch of errors, no new line at end of file, implicit declarations, and some parse errors.