作者ric2k1 (Ric)
看板EE_DSnP
標題[討論] 另外一個關於 Prob 4-1 的問題
時間Sun Nov 11 15:45:23 2007
關於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