看板 EE_DSnP 關於我們 聯絡資訊
關於4-1題 我寫的程式都能滿足題目的要求 即他的誤差值都小於accuracy 可是interations沒有老師的那麼多次 這樣可以嗎? cout<<"please enter the desired accuracy "<<endl ; cin>>accuracy ; while (max(pi , 3.141592653)-min(pi , 3.141592653) > accuracy) { interation++ ; pi = pi+pow ( -1.0 , interation ) * 4.0/(1.0+2.0*interation) ; } >>>>>>>>>>>>>>>> 你這樣的寫法會有 chicken-and-egg 的問題! The purpose of this problem is to compute the value of "pi". However, you compare the value with the constant 3.141592653, which should be the result we want to compute. Please try another method to estimate the "accuracy" (or say "difference"). BTW, to alternate the sign of the new term, you use "pow(-1.0, iteration)". This is more time-consuming than necessary. Please refer to post 678 in the BBS. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.135.212