calculate the value of pi from in finite series
pi=4-(4/3)+(4/5)-(4/7)+(4/9)-(4/11)....
print a table that shows the approximate value of pi 1,000 terms series

Recommended Answers

All 8 Replies

Well i think that you should post your code until where you have worked on.

commented: *agrees* +26

calculate the value of pi from in finite series
pi=4-(4/3)+(4/5)-(4/7)+(4/9)-(4/11)....
print a table that shows the approximate value of pi 1,000 terms series

How the value of PI can be printed as a table?

How the value of PI can be printed as a table?

That's a difficult one:

#include <iostream>
int main()
{
    std::cout << "|value of PI:|\n|------------|\n|   3.14     |\n|------------|\n";
    return 0;
}
commented: I like my pies on the table ;) +26

I think its got to do with the progression thats going on.

try using a for loop. with a function that calculates the valuse of a pi.

int calcpi(int a)
{
// Let this sequence come in (pi=4-(4/3)+(4/5)-(4/7)+(4/9)-(4/11)....)
}

Well we can see that its an arithmatic progression, So you can work out the values with the formula

a+nd

where

a= starting val.
n= number to which its being calculated
d= is the common difference

Well hope this sorted your question out.

arctan(1)=pi/4 wich means : the arc wich has 1 as tan is equal to pi/4 radians.
SEries expansion gives :
arctan(1) = 1-1/3+1/5-1/7....
so pi/4 = 1-1/3+1/5-1/7....
1-1/3+1/5-1/7....can be easily computed.

This is the worst assignment I have ever seen.

The series is the Geogory-Leibniz series. It is one of the slowest convergent series for pi. You need about to sum 300 terms to get 3.14 accurately, to get 10 digits you need about 10 billion terms and to get to 1000 digits you are in the realms of needing more computations than atoms in the universe (by a long way!).

I note that there are some transforms that get the convergence quickly (see wolfram site) , if that was the intention of the question, fine, but otherwise it is a very stupid question.

If you want to get pi accurately then you can use Brent–Salamin algorithm http://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm
formula.

But this is a computing forum so I HAVE to give credit to the
Bailey–Borwein–Plouffe formula.

pi=\sum_0^\infty (\frac{1}{16^k} (
\frac{2}{8k+1}- \frac{4}{8k+4} -\frac{1}{8k+5}-\frac{1}{8k+6})


This allows you to calculate JUST one digit (in hex) at a time.
Stunning in its elegance!!

Member Avatar for iamthwee

> if that was the intention of the question, fine, but otherwise it is a very stupid question.

Maybe it was. (assuming you take midpoints of partial sums)
http://en.wikipedia.org/wiki/Leibniz_formula_for_pi

Also shouldn't the Bailey–Borwein–Plouffe formula be:

(\frac{4}{8k+1}-\frac{2}{8k+4} etc ?

commented: thanks for correcting my mistake +3

Well pointed out iamthwee, you are completely correct. about eh
BBP formula. Sorry for getting that wrong.

As to using partial sums... even with the midpoint sum the number of terms required is huge -- but point taken!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.