级数思想:在微积分中,对一个表达式进行级数展开并极限便可以得到一系列的迭代计算公式
PI
PI
pi / 2 = 1 + 1/3 + 1/3 * 2/5 + 1/3 * 2/5*3/7+ 1/3 * 2/5*3/7*4/9+......
// JiShuPI.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <IOSTREAM>
#include <CSTDIO>
#include <CSTDLIB>
using namespace std;
double JiShuPI()
{
double PI = 2,tmep = 2;
int n = 1,m = 3;
while(tmep > 1e-15)
{
tmep = tmep * n / m;
PI += tmep;
n++;
m+=2;
}
return PI;
}
int main(int argc, char* argv[])
{
double PI;
PI = JiShuPI();
printf("PI = %f\n", PI);
return 0;
}