Please visit our sponsor
UNKNOWN //************************************** //INCLUDE files for :Precise Calculation of Pi //************************************** iostream.h math.h //************************************** // Name: Precise Calculation of Pi // Description:This code calculates an estimated value of Pi using the Leibnitz series (which is basically a power series expansion of a trigonometric function which allows to estimate Pi very well) // By: Eli // // // Inputs:n/a // // Returns:Prints the estimated value of Pi // //Assumes:n/a // //Side Effects:n/a //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.360/lngWId.3/qx/vb/scripts/ShowCode.htm //for details. //************************************** #include <iostream.h> #include <math.h> #define NUM_OF_ELEMENTS 20000 int main() { double pi = 0; // Calculating pi/4 for (long int n = 1; n &lt;= NUM_OF_ELEMENTS; n++) { pi += (double) pow(-1, n+1)/(2*n-1); } // Calculating pi pi *= 4; cout &lt;&lt; "Estimated PI value (" &lt;&lt; NUM_OF_ELEMENTS &lt;&lt; " elements of Leibnitz series): "&lt;&lt; pi; return 0; }