Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Multidimension array problem. I can't figure out why the last column is different (http://www.go4expert.com/forums/multidimension-array-i-figure-column-t19501/)

 warmsheet 21Sep2009 22:25

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

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??

 warmsheet 21Sep2009 22:26

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

Sample output: img28.imageshack.us/i/output.jpg/
Screenshot of program: img142.imageshack.us/i/programl.jpg/

 warmsheet 21Sep2009 22:31

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

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.

 warmsheet 21Sep2009 23:20

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

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.

 All times are GMT +5.5. The time now is 05:36.