I'm not sure what's wrong, i get the wrong the answers for x, i should be getting:

x0=1

x1=-1

x2=1

Code:

int main()
{
int n = 3, i = 0, j = 0, k = 0;
double m = 0;
double *b;
b = new double[n];
b[0]=0; b[1]=3; b[2]=2;
double *x;
x = new double[n];
double **A;
A = new double *[n];
for(int i=0; i<n; i++)
A[i] = new double [n];
A[0][0]=1; A[0][1]=2; A[0][2]=1;
A[1][0]=2; A[1][1]=2; A[1][2]=3;
A[2][0]=-1; A[2][1]=-3; A[2][2]=0;
for (int k=0; k<=n-2; k++)
{
for (int i=k+1; i<=n-1;i++)
{
double m = A[i][j]/A[k][k];
for (int j=k; j<=n-1; j++)
A[i][j] = A[i][j] - m*A[k][j];
b[i] = b[i] - m*b[k];
}
}
x[n-1] = b[n-1]/A[n-1][n-1];
for (k=n-2; k>=0; k--)
{
x[k]=0;
for (j=k+1; j<=n-1; j++)
x[k] = x[k] + A[k][j] * x[j];
x[k] = (b[k] - x[k])/A[k][k];
}
cout << x[1];
system ("pause");
return 0;
}