Level 2 c program design question (2), c program design question
Original article: http://www.cnblogs.com/imaker/p/6128049.html
Year: 2010.9; 2012.3
Compile the function fun. Its function is to calculate the π value based on the following formula (accuracy 0.0005 is required, that is, to stop iteration when a certain item is less than 0.0005 ).
After the program runs, if the input precision is 0.0005, the program should output 3.14 ....
Note: Some source programs are in the PROG1.C file.
Do not change the main function or any content in other functions. Just fill in the brackets of function fun with several statements you have written.
The Code is as follows:
# Include <stdio. h> # include <conio. h> # include <math. h> double fun (double eps) {double s = 1.0, sl = 1.0; int n = 1; while (sl> = eps) {sl = sl * n/(2 * n + 1); s = s + sl; n ++;} return 2 * s;} void main () {double x; printf ("Input eps:"); scanf ("% lf", & x); printf ("\ neps = % lf, PI = % lf \ n", x, fun (x ));}
As follows:
:
Thank you for reading this article! Hope it can help you !! Sharing is also a pleasure !!! Please relay...