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

warmsheet's Avatar, Join Date: Sep 2009
Newbie Member
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 shabbir; 22Sep2009 at 10:04.. Reason: Code blocks
0
warmsheet's Avatar, Join Date: Sep 2009
Newbie Member
Sample output: img28.imageshack.us/i/output.jpg/
Screenshot of program: img142.imageshack.us/i/programl.jpg/
0
warmsheet's Avatar, Join Date: Sep 2009
Newbie Member
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.
0
warmsheet's Avatar, Join Date: Sep 2009
Newbie Member
Uhm, sorry. It's okay now. Somebody helped me figure it out. It seems I forgot that the array size will end at column deg-1 so I had to increase my size by 1.