this is a piece of code for a simple iteration method for solving systems of linear algebraic equations:
double* iter(double** a, double* y, int n, int& iter)
{
    double* res = new double[n];
    int i, j;
    
    for (i = 0; i < n; i++)
    {
        res[i] = y[i] / a[i][i];
    }
    double eps = 0.0001;
    double* Xn = new double[n];
    do {
        iter++;
        for (i = 0; i < n; i++) {
            Xn[i] = y[i] / a[i][i];
            for (j = 0; j < n; j++) {
                if (i == j)
                    continue;
                else {
                    Xn[i] -= a[i][j] / a[i][i] * res[j];
                }
            }
        }
        bool flag = true;
        for (i = 0; i < n - 1; i++) {
            if (fabs(Xn[i] - res[i]) > eps) {
                flag = false;
                break;
            }
        }
        for (i = 0; i < n; i++) {
            res[i] = Xn[i];
        }
        if (flag)
            break;
    } while (1);
    return res;
}
but I would like to implement the seidel method.and slightly changed the code according to the formula below
for (i = 0; i < n; i++) {
            Xn[i] = y[i] / a[i][i];
            for (j = 0; j < i-1; j++) {
                    Xn[i] -= a[i][j] / a[i][i] * Xn[j];
            }
            for (j = i+1; j < n; j++){
                Xn[i] -= a[i][j] / a[i][i] * res[j];
            }
        }
but I'm not getting exactly what I expected:
I would be grateful if you could tell me where I made a mistake. thank you in advance for your answers.




 
    