Program that estimates the value of the mathematical pi.

Hi, I need some help.

I need to write a program that estimates the value of the mathematical constant pi. The infinite
series used to approximate it is shown below. The program should calculate it up to the
'n'th term as given by the user. It should also display each 'k'th calculation as given by the
user. The first 6 elements of the series calculation are shown below.

π = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + etc...

those are fractions by the way.


If anyone could give me a full working program for this, i'd be forever in your debt.
Last edited on
You need to implement something like a sum [ ( - 4 )^n / (2*n+1) ]

 
#include <cmath> // You need this to use power function (x^a) 


And then you can write like this.

1
2
3
    double total = 0;
    for (int i = 0; i <= n; i++)
        total += (pow(-4, i) / (2 * i + 1));


Maikel
Last edited on
Topic archived. No new replies allowed.