"Writing a program in C + + to find the value of pi"

Source: Internet
Author: User
Tags value of pi

1 //Write a C + + program to find the value of pi2 /*3 Pi=16arctan (1/5) -4arctan (1/239)4 where arctan is calculated using the following form of pole number:5 arctan=x-(X^3/3) + (X^5/7)-(X^7/7) + ...6 */7#include <iostream>8 using namespacestd;9 DoubleArctanDoublex) {Ten     DoubleSQR = x*x; One     DoubleE =x; A     DoubleR =0; -     inti =1; -      while(e/i>1e- -){ the         Doublef = e/i; -R = (i%4==1)? r+f:r-F; -E = e*Sqr; -i+=2; +     } -     returnR; + } A intMain () at { -     DoubleA =16.0*arctan (1/5.0); -     Doubleb =4.0*arctan (1/239.0); -cout<<"pi="<<a-b<<Endl; -System"Pause"); -     return 0; in}

"Writing a program in C + + to find the value of pi"

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.