Advertisement
2002C Math #15959

Precise Calculation of Pi

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)

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
#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;
}
Commenti originali (3)
Recuperato da Wayback Machine