title: How to solve n equation with Jacobi method by C++?
body: <p>This code should get</p>
  
  <ul>
  <li>number of equations (n)</li>
  <li>matrix a</li>
  <li>matrix b</li>
  <li>accuracy of answer (e)as input</li>
  </ul>
  
  <p>And then find the answer of <strong>n</strong> equations by <strong>Jacobi</strong> method.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>     #include &lt;cstdlib&gt;
       #include &lt;iostream&gt;
       #include &lt;conio.h&gt;
       #include &lt;math.h&gt;
  
  using namespace std; // DEV software code for using 'cin' instead 'scanf' 
  int main()
  {
      int n,i,j,l=0;
      cout&lt;&lt;"Enter number of Equations = ";
      cin&gt;&gt;n;
      double a[n-1][n-1],b[n-1][1],x[n-1][1],T[n-1][1],e,k;
      cout&lt;&lt;"[a].[x]=[b]"&lt;&lt;endl;
      cout&lt;&lt;"Enter Matrix a:"&lt;&lt;endl;
      for(i=0;i&lt;n;i++)
      for(j=0;j&lt;n;j++)
      {
          cout&lt;&lt;"a["&lt;&lt;i&lt;&lt;","&lt;&lt;j&lt;&lt;"] = ";
          cin&gt;&gt;a[i][j];
      }
      cout&lt;&lt;"Enter Matrix b:"&lt;&lt;endl;
      for(j=0;j&lt;n;j++)
      {
          cout&lt;&lt;"b[0,"&lt;&lt;j&lt;&lt;"] = ";
          cin&gt;&gt;b[0][j];
      }
      cout&lt;&lt;"Enter the Accuracy = ";
      cin&gt;&gt;e;
      for (i=0;i&lt;n;i++)
          T[i][0]=0;
      while (l!=n)
      {
          l=0;
          for (i=0;i&lt;n;i++)
          {
              x[i][0]=(1/a[i][i])*(b[i][0]);
              for (j=0;j&lt;n;j++)
              {
                  if (j!=i)
                  x[i][0]=x[i][0]-(1/a[i][i])*(a[i][j]*T[j][0]);
              }
          }
          for(i=0;i&lt;n;i++)
          {
              k=fabs(x[i][0]-T[i][0]);
              if (k&lt;=e)
              {
                  l=l+1;
              }
          }
      for (i=0;i&lt;n;i++)
          T[i][0]=x[i][0];
      }
      for (i=0;i&lt;n;i++)
          cout&lt;&lt;"x"&lt;&lt;i+1&lt;&lt;"="&lt;&lt;x[i][0]&lt;&lt;endl;
      getch();
      return 0;
  }
  </code></pre>
  
  <p><strong>For example:</strong> (e.g.)</p>
  
  <pre><code>     // Initializing variables
  n=2
  e=0.001
  a[0,0]=4
  a[0,1]=2
  a[1,0]=1
  a[1,1]=3
  b[0,0]=1
  b[1,0]=-1 
  </code></pre>
  
  <p>The answer should be <code>x1=0.5</code> and <code>x2=-0.5</code>. But the output of this code is <code>x1=0.35</code> and <code>x2=-0.45</code>.</p>
  
  <p>What's the problem?</p>
  
  <p>Regards</p>