訪客只能看到部份內容,免費 加入會員 或由臉書 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 ; }