title: Gauss Jordan Method in Basic C Multi
body: <p>I am have a multi-dimensional array that needs to be resolved, to solve for the unknown values (x1,x2,x3,..). In this multi-dimensional array, my array size in the i and j coordinate are different; B[n][n+1]. I know this Basic C, Gauss Jordan Method to solve for the unknown, is incorrect and would like someone to point in how to modify it.. </p>
  
  <p>This code is accurate for an Array with the same n values only; eg. A[n][n].</p>
  
  <pre><code>//Computation to solve
  for(j=0; j&lt;=n; j++)
  {
      for(i=0; i&lt;=n; i++)
      {
          if(i!=j)
          {
              c=B[i][j]/B[j][j];                    
              for(k=0;k&lt;=n+1;k++)
              {
                  B[i][k] = B[i][k] - c*B[j][k];
              }
          }
      }
  }
  
  //Print Solution
  printf("\nThe solution is:\n");
  for(i=0; i&lt;=n; i++)
  {
      x[i]=B[i][n+1]/B[i][i];
      printf("\n x%d=%.3f\n",i,x[i]);
  }
  </code></pre>
  
  <p>An example would be if my n=2. The array that i would want to solve is B[2][3].</p>
  
  <pre><code>0  -20  0  -1
  0  30  -10  0
  0  -10  10  1
  </code></pre>
  
  <p>The output of this code is </p>
  
  <pre><code>x1= -inf 
  x2=0.050
  x3=0.000
  </code></pre>
  
  <p>The correct output should be </p>
  
  <pre><code>x1=0.00
  x2=0.05
  x3=0.15
  </code></pre>