title: How to calculate sum of Pi
body: <p>I posted not long ago on how to compute the sum of Pi with openmp. But it seems something's off with my code. Because manually I get the right result, but when I program it, it gives wrong results, if someone can help me?</p>
  <p>PS : s= 1/N</p>
  <p><a href="https://i.stack.imgur.com/2FQdJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2FQdJ.png" alt="Sum of pi" /></a></p>
  <pre><code>#include &lt;chrono&gt;
  #include &lt;iostream&gt;
  
  double f(double x)
  {
    return (4 / (1 + (x * x)));
  }
  
  int main()
  {
      int i;
      const int N = 60;
      double s1=0.0; double s2=0.0; double s3=0.0;
      double pi = 0.0; double s4=0.0; double s5=0.0;
      
      for (int i=0; i&lt;N; i++)
          {
              //pi+=((f(i/N)+f((i+1)/N))/2*N);
              s1 = f(i/N);
              s2 = f((i+1)/N);
              s3 = 2 * N;
              s4 = s1 + s2;
              s5 = s4 / s3;
              pi+=s5;
          }
          
    printf(&quot;Pi = %f&quot;,pi);
    return 0; 
  }
  </code></pre>