Thread: Determinant Prob

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

    Determinant Prob

    where does the floating point error: divide by 0 occur

    can anyone help me with this


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

    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(0);
    }

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    21
    how do u put the code here with the formatting....when i post it....the indents go away

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Use the [code][/code] forum bbcode tags.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by dantu1985 View Post
    how do u put the code here with the formatting....when i post it....the indents go away

    Use the code tags

    It's symbolized by the # sign when you a posting.

  5. #5
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    My maths isn't that great...but aren't determinants for matrices integers and not floating point numbers?

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    21
    hey pls help me on that floating point error...

    i changed to int...still not working...

    i have mult = a[j][i]/a[i][i]

    so mult is float and so is a array

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Closed - for multi posting the same thing without code tags.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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: 2
    Last Post: 08-19-2007, 12:00 AM
  5. determinant?! HELP!!!
    By ankurtrick in forum C Programming
    Replies: 1
    Last Post: 10-08-2004, 09:12 PM