0

I wrote a c++ program to calculate pi using the infinite expansion for pi/4. I've used long double but still i get pi = 3.14158 . Where is the extra decimal chopped off. How to correct it? So is this is my code :

#include<iostream>
#include<math.h>
using namespace std;

int main(void)
{
    long double pi=1,si,i;

    for(i=1;i<100000;i++)
    {
        si = (pow(-1.0 ,i))/(2*i+1);
        pi += si;
    }

    pi*=4.0;
    cout<<"  "<< pi <<" \n ";
}
Grimm The Opiner
  • 1,778
  • 11
  • 29

1 Answers1

1

Your problem here is not the actual accuracy of the computed number, but in the formatting of your displayed output. Check this answer for details.

Community
  • 1
  • 1
Logicrat
  • 4,438
  • 16
  • 22