//**************************************
//
// Name: Precise Calculation of Pi
// Description:This code calculates an e
// stimated value of Pi using the Leibnitz
// series (which is basically a power serie
// s 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/txtCod
// eId.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 <= 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;
}