作者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