/**
*求PI,用正多边形逼近法、数值概率算法
**/
#include<stdio.h>
#include<math.h>
double getPI(int n);
int main()
{
int n = 1;
double PI;
printf("please input the accuracy:\n");
scanf("%d",&n);
PI = getPI(n);
printf("the similar value of PI is :\n%f\n",PI);
getchar();
return 0;
}
double getPI(int n)
{
int i = 4;
double b = sqrt(2)/2.0;
for(int div = 0;div < n;div++)
{
b = sqrt(2.0 - 2.0 * sqrt(1.0-b*b))*0.5;
i *= 2;
}
return b * i;
}
//(to be continued)