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+.....

triffid1962Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BatalfConnect With a Mentor 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
 
BatalfCommented:
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
 
BatalfCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
BatalfCommented:
Could this help you?

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
 
ozoCommented:
what doesn't seem to work?
0
 
BatalfCommented:
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
 
triffid1962Author Commented:
Ok  It'll do for now.I'll see what I can do with it.Thanks
0
All Courses

From novice to tech pro — start learning today.