访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容
#include <iostream> #include <cmath> using namespace std; int main() { int ct = 1 , i ; double pi0 , pi1 , total = 0 , diff = 10 , MaxError ; cout << "输入MaxError ==>" ; cin >> MaxError ; pi0 = sqrt ( 1 * 6 ) ; while ( MaxError < diff ){ ct = ct + 1 ; for ( i = 1 ; i <= ct ; i++ ){ total = total + (1 / pow ( i , 2.0 )) ; } pi1 = sqrt ( total * 6 ) ; total = 0 ; diff = pi1 - pi0 ; pi0 = pi1 ; } pi0 = pi1 - diff ; //所以pi0=pi1-diff cout << "ct = " << ct << endl; cout << "preApprox = " << pi0 << endl; cout << "newApprox = " << pi1 << endl; cout << "diffApprox = " << diff << endl; system("pause") ; return 0 ; }