/* calculation of pi: approximating a circle by polygons */ #include #include #include using namespace std; int main() { int nsides = 6; double length = 1.; for(int i=0;i<27;i++) { length = sqrt(2. - sqrt(4. - length*length)); nsides *= 2; double pi = length*(double)nsides/2.; // cout << fixed; cout << setw(10) << nsides << "\t" << setprecision(16) << pi << "\t" << fabs(M_PI-pi) << endl; } }