Known to use the following formula to calculate PI approximation, given a PI approximation e, a programming using the following formula for the closest e and less than the approximate value of e PI, as well as the number of iterations n (greater than or equal to 1),
Two-thirds of PI/2=2/1 (x) (four thirds 4/5) x x x x x 6/7 (6/5)... X (2 n/(2 n - 1) x2n/(2 n + 1)]
[form] input
From the console input e (e is greater than 2.6666667, less than 3.1415926) the value of the
[] output form
Output is the closest to and less than the approximate value of e e PI, as well as the number of iterations n (with a space space, and the output of PI when seven valid decimal Numbers),
[sample input]
3.12
[sample output]
3.1195472 35
[example]
Input of PI approximation e 3.12, when the n is 35 calculated PI value of 3.1195472, less than the value of the given precision, when n is 36, calculation of PI value of 3.1201491, is greater than the value of the given precision, so the closest e and using the above formula obtained is less than e PI approximation is 3.1195472, corresponding to the number of iterations of 35,
Note:
In order to ensure the calculation precision, please use the double data type calculation data save,
#include
Int main ()
{
double x;
float y;
Float f (double x);
Printf (" please input Π: ");
The scanf (" % f ", & amp; X);
Printf (" % 7 lf ", 2 * y);
;
}
Float f (double) a
{
Float k;
for(int i=1; 2 * k<=a; I++)
{
Float m;
I/m=2 * (2 * I - 1) * 2 * I/(2 * I + 1);
K=k * m;
}
The return of k;
}
CodePudding user response:
Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day! Return card can get 10 points available every day!CodePudding user response:
Child function f, k without an initial value, so for the first time will determine failure, jump outCodePudding user response:
Also, although I don't know why you use double x, but since using the double, the input, please use the scanf (" % lf ", & amp; x)CodePudding user response:
I - I/(2 * 2 * 1) * 2 * I/(2 * I + 1) there is always an integer arithmeticIt is good to change the first 2 to 2.0
Otherwise this is integer arithmetic, although m is a floating point number, the result of the class integer arithmetic is always 0 have a fart to use
CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html