I want to write a program to calculate Pi:
Pi=4-4/3+4/5-4/7+4/9-4/11+...
(the user inputs the number of terms in the series)
Is this right ?
#include<iostream>
using namespace std;
int main ()
{
double n=4.0;
double d=1.0;
double pi;
cout<<"Enter the number of terms in the series";
cin>>n>>d;
while(d<=10)
{
d=d+2;
n=-n;
pi=n/d;
cout<<"Pi="<<pi<<endl;
}
system("pause");
return 0;
}