标签:include term using 1.0 break std int ++ double
计算:PI/4=1-1/3+1/5-1/7+...,直达最后一项小于10-6
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double sum=0;
for(int i=0;;i++)
{
double term=1.0/(i*2+1);
if(i%2==0)
sum+=term;
else
sum-=term;
if(term<1e-6)
break;
}
printf("%.6f\n",sum);
return 0;
}
标签:include term using 1.0 break std int ++ double
原文地址:http://www.cnblogs.com/Aftersoon-sun/p/6270519.html