时间:16.4.12
文件:app.cpp
问题描述:累加法求圆周率
#include <iostream>
using namespace std;
int main( )
{
int n,sign;
double total,f;
n=1;
total=0;
sign=1;
f=1;
while(f>1e-5)
{
total+=(sign*f);
n+=2;
f=1.0/n;
sign*=-1;
}
cout<<"total="<<4*total<<endl;
return 0;
}
文件:app.cpp
问题描述:累加法求圆周率
#include <iostream>
using namespace std;
int main( )
{
int n,sign;
double total,f;
n=1;
total=0;
sign=1;
f=1;
while(f>1e-5)
{
total+=(sign*f);
n+=2;
f=1.0/n;
sign*=-1;
}
cout<<"total="<<4*total<<endl;
return 0;
}