Thread: Determinant Prob

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    21

    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

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    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.

  3. #3
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fast Determinant evaluator
    By jack_carver in forum C Programming
    Replies: 2
    Last Post: 12-28-2009, 08:42 PM
  2. matrix determinant
    By roaan in forum C Programming
    Replies: 1
    Last Post: 06-30-2009, 12:44 PM
  3. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  4. Determinant Prob
    By dantu1985 in forum C Programming
    Replies: 6
    Last Post: 08-19-2007, 12:40 AM
  5. determinant?! HELP!!!
    By ankurtrick in forum C Programming
    Replies: 1
    Last Post: 10-08-2004, 09:12 PM