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
#include
#define NUM_OF_ELEMENTS 20000
int main()
{
double pi = 0;
// Calculating pi/4
for (long int n = 1; n <= NUM_OF_ELEMENTS; n++)
{
pi += (double) pow(-1, n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << "Estimated PI value (" << NUM_OF_ELEMENTS << " elements of Leibnitz series): "<< pi;
return 0;
}