Not Yet Answered # pi.cpp

kbshibukumar 1 Nick Evan 4,005 Sky Diploma 571 ddanbe 2,503 StuXYZ 731 iamthwee 1,547 StuXYZ 731 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

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?

1

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;
}
```

0

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.

0

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.

0

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!!

0

> 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 ?

0

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!

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...