Multidimension array problem. I can't figure out why the last column is different

Discussion in 'C' started by warmsheet, Sep 21, 2009.

  1. warmsheet

    warmsheet New Member

    Joined:
    Sep 21, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I'm sorry. I really need help on this. I even made a shorter and simpler program that I think is enough to show my problem.

    This is the example program:


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
    int i, j, deg, points;
    
    printf("Enter degree of polynomial equation: "); scanf("%i", &deg); 
    printf("Enter number of points: "); scanf("%i", &points);
    float xs[points-1], Fmat[points][deg];
    for(i=0; i<points; i++)
    {printf("x%i = ", i); scanf("%f", &xs[i]);}
    printf("\n");
    
    for(i=0; i<points; i++)
    for(j=0; j<deg+1; j++)
    Fmat[i][j]=pow(xs[i],1);
    
    
    for(i=0; i<points; i++)
    {for(j=0; j<=deg; j++)
    printf("%ii%ij:%7.3f\t", i,j,Fmat[i][j]);
    printf("\n");}
    
      system("PAUSE");	
      return 0;
    }


    Now, my problem is that it is printing (and probably storing) the right values EXCEPT on the last column.

    This is greatly confusing me and I've spent my whole night trying to figure it out (to no avail, obviously). I'm sorry for the dumbness of my problem but will somebody please help me figure it out??

    Thanks in advance.
     
    Last edited by a moderator: Sep 22, 2009
  2. warmsheet

    warmsheet New Member

    Joined:
    Sep 21, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Sample output: img28.imageshack.us/i/output.jpg/
    Screenshot of program: img142.imageshack.us/i/programl.jpg/
     
  3. warmsheet

    warmsheet New Member

    Joined:
    Sep 21, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    And I'm sorry. It's late that I read I need to enclose the code within code. I can't seem to edit it. I'm really sorry.
     
  4. warmsheet

    warmsheet New Member

    Joined:
    Sep 21, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Uhm, sorry. It's okay now. Somebody helped me figure it out. :nice: It seems I forgot that the array size will end at column deg-1 so I had to increase my size by 1.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice