Level 2 c program design question (2), c program design question

Source: Internet
Author: User

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...

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.