title: I wrote this C program for Jacobi iterative method but I am getting Nan and infinity as output I tried changing from
body: <ol>
  <li>I am getting Nan and infinity as output I tried changing  from <code>float</code> to <code>double</code></li>
  <li><p>Maybe error is in accuracy ?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;math.h&gt;
  
  double u(double w,double x,double y,double z)
  {
    return ( (-22*x+2*y-4*z+3)/3);
  }
  
  double f(double w,double x,double y,double z)
  {
    return ((36*w+y-3*z-4)/2);
  
  }
  
  double s(double w,double x,double y,double z)
  {
    return ((w-2*x-40*z+6)/4);
  
  }
  
  double t(double w,double x,double y,double z)
  {
    return ((-2*w-3*x-38*y+8)/2);
  
  }
  
  void main()
  {
    double w0,x0,y0,z0,w1=0,x1=0,y1=0,z1=0,tempw,tempx,tempy,tempz,acc=0.000001;
    int iteration=0;
    printf("Enter initial guesses:\n");
    scanf("%f%f%f%f",&amp;w0,&amp;x0,&amp;y0,&amp;z0);
    do
    {
      tempw=w1;
      tempx=x1;
      tempy=y1;
      tempz=z1;
      w1=u(w0,x0,y0,z0);
      x1=f(w0,x0,y0,z0);
      y1=s(w0,x0,y0,z0);
      z1=t(w0,x0,y0,z0);
  
      iteration++;
      w0=w1;
      x0=x1;
      y0=y1;
      z0=z1;
    }while(fabs(tempw-w1)&gt;acc &amp;&amp;fabs(tempx-x1)&gt;acc &amp;&amp; fabs(tempy-y1)&gt;acc 
        &amp;&amp; fabs(tempz-z1)&gt;acc);
  
    printf("\n\nFinally,\n");
    printf("w=%f Ans\nx=%f Ans\ny=%f Ans\nz=%f Ans\n",w1,x1,y1,z1);
    printf("Iteration=%d",iteration);
    getch();
  
  }
  </code></pre></li>
  </ol>