The value of pi can be approximated using a series.
pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ... + 1/(2n-1) - 1/(2n+1))
Write a program to let the user input n number of terms to approximate pi value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std;
int main()
{
double pi,x;
int n;
cout<<"Enter n terms: ";
cin>>n;
for (int i=1;i<=n;i++)
{ x = (1/(2*i-1)) - (1/(2*i+1));
pi=4*x;
cout<<"pi = "<<pi<<endl;
}
return 0;
}