# evaluating Pi

How would I solve this equation in a program? I know I need at least one FOR TO loop,but how would I do the fractions? I saw a question someone asked about fractions,but it doesn't seem to work.

Pi/4= 1-1/3+1/5-1/7+1/9-1/11+.....

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Hi triffid1962

Could you explanin this mathematical function a little bit more and I would give you some code ASAP :-)

Maybe type down an example

Batalf
0
Commented:
Hi triffid1962

Could you explanin this mathematical function a little bit more and I would give you some code ASAP :-)

Maybe type down an example

Batalf
0
Commented:

A saying says :
"We would need to compute five million terms just to get /4 to 6 (or 7) decimal places! "

var
i : longint;
pi : real;

begin
pi:=1;
for I:=3 to 5000000 step 4 do
end;
pi:=pi-(1/i);
pi:=pi+(1/(i+2));
end;
end.
0
Commented:
what doesn't seem to work?
0
Commented:
In case the "step" command doesn't work

PROGRAM evaluatePI;
var
i : longint;
pi : real;

begin
pi:=1;
I:=3;
repeat
pi:=pi-(1/i);
pi:=pi+(1/(i+2));
i:=i+4;
until i>=5000000;
writeln(pi);
pause;
end.
0
Commented:
HI

Forgot pi:=pi*4 in the code :-)

PROGRAM evaluatePI;
var
i : longint;
pi : real;

begin
pi:=1;
I:=3;
repeat
pi:=pi-(1/i);
pi:=pi+(1/(i+2));
i:=i+4;
until i>=5000000;
pi:=pi*4 {forgot this one}
writeln(pi);
pause;
end.
0

Experts Exchange Solution brought to you by