Calculate the circumference rate by using the Newton series, 15 decimal places after the decimal point, Newton's circumference Rate

Source: Internet
Author: User

Calculate the circumference rate by using the Newton series, 15 decimal places after the decimal point, Newton's circumference Rate

In the 18th century, mathematicians developed a number of Infinite Series for calculating the circumference rate. Among them, Newton studied the following series:

This Infinite Series is used to calculate the circumference rate to 15 digits after the decimal point.

 

Method: perform the following simple deformation on the above formula to conveniently compile the program.

 

 

 1 #include <iostream> 2 #include <iomanip> 3 using namespace std; 4  5 int main( void )    /* name: Pinew.cpp */ 6 {    double s, t, p; 7     int a, b, n; 8     s=3.0;    t=3.0;    a=1;    b=2;    n=0; 9     cout<<fixed<<setprecision(15);10     do11     {   t=0.25*t*a/b;12         p=t/(a+2);13         s+=p;14         n++;15         cout<<"n="<<setw(4)<<n<<"  Pi="<<s<<endl;16         a+=2;17         b+=2;18     }while(p>=1E-18);19     20     return 0;21 }

Running result:

N = 1 Pi = 3.125000000000000
N = 2 Pi = 3.139062500000000
N = 3 Pi = 3.141155133928572
N = 4 Pi = 3.141511172340030
N = 5 Pi = 3.141576715774867
N = 6 Pi = 3.141589425319122
N = 7pi = 3.141591982358383
N = 8 PIOs = 3.141592511157862
N = 9 Pi = 3.141592622870617
N = 10pi = 3.141592646875561
N = 11 Pi = 3.141592652105887
N = 12 Pi = 3.141592653258738
N = 13 Pi = 3.141592653515338
N = 14 Pi = 3.141592653572930
N = 15 Pi = 3.141592653585950
N = 16 Pi = 3.141592653588912
N = 17 Pi = 3.141592653589590
N = 18 Pi = 3.141592653589746
N = 19 Pi = 3.141592653589782
N = 20 PIOs = 3.141592653589790
N = 21 Pi = 3.141592653589792
N = 22 PIOs = 3.141592653589793
N = 23 Pi = 3.141592653589793
N = 24 Pi = 3.141592653589793
N = 25 Pi = 3.141592653589793
N = 26 Pi = 3.141592653589793
N = 27 PIOs = 3.141592653589793

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.