Calculate the value of π from the infinite series
π=4-4/3+4/5-4/7+4/9-4/11.........
Print a table that shows the approximate value of π after each of the first 1000 terms of this series.
#include <iostream>
using namespace std;
int main()
{
long pi=4;
int n=999 ; //each of the first 1000 terms of this series
double s; //分母
for(int i=0;i<=n;i=i+2)
{
s=i+s;
pi = pi + 4/-s;
}
cout<<"pi的值為:"<<pi<<endl;
return 0;}
謝~